Machine Learning With ML - Net and C# - VB - Net - CodeProject

September 1, 2022 | Author: Anonymous | Category: N/A
Share Embed Donate


Short Description

Download Machine Learning With ML - Net and C# - VB - Net - CodeProject...

Description

 

28/06/2018

Machine Learning with ML.Net and C#/VB.Net - CodeProject

Machine achine Learning  Learning with ML.Net and C#/VB.Net Bahle, 28 Jun 2018 Dirk Bahle,

Solving the Classification Classification problem problem with ML.Net Version 0.2.

Wikipedia_Sentiment Wiki pedia_SentimentAnalysis.zip Analysis.zip

Wikipedia_SentimentAnalysis_VB.zip

YouGotSpam_Analy YouGotS pam_Analysis.zip sis.zip

YouGotSpam_Analysis_VB.zip

LanguageDetection.zip LanguageDete ction.zip

LanguageDetection_VB.zip

IrisClassification.zip IrisClassi fication.zip

IrisClassification_VB.zip

IrisClassification_  IrisC lassification_ uint.zip uint.zip

IrisClassification_uint_VB.zip

Index Inde x Introduction Background Overview Supervised Machine Supervised  Machine Learning Binary Classification Sentiment Analysis Wikipedia Wikipedia Training Stage Prediction Stage You Got Spam Multiclass Classification Language Detection Iris Flower Classification Version 1 Version 2 Conclusions References History

Introduction This article introduces machine learning in .Net without touching the mathematical side of things. It will focus on essential workflows and their structures of the data handling in .Net to facilitate experimentation with what is available in an open source project ML.Net version 0.2. 0.2. The ML.Net project version 0.2 0.2 is  is available for .Net Core 2.0 and 2.0 and .Net Standard 2.0 with 2.0 with support for x64 x64 architecture  architecture only (Any CPU will not compile right now). It should, thus, be applicable in any framework where .Net Standard 2.0 (eg.: 2.0 (eg.: .Net Framework 4.6.1) is applicable. The project is currently on review. APIs may change in change in the future.

Background htt https: ps://w //www ww.cod .codepr eproje oject. ct.com/ com/Art Article icles/1 s/1249 249611 611/Ma /Machi chinene-Lea Learn rning ing-wi -withth-ML ML-Ne -Net-a t-andnd-Csh Csharp arp--VBVB-Net Net?di ?displ splay= ay=Pr Print int

1/17 1/17

 

28/06/2018

Machine Learning with ML.Net and C#/VB.Net - CodeProject

Learning the basics of machine learning has not not been easy, if you want to use an object oriented language like C# or VB.Net. Because most of the time you have to learn Python, before anything else, and then you have to find tutorials with sample data that can teach you more. Even looking at object oriented projects like [1] Accord.Net, Tensor.Flow, or CNTK is not easy because each of them comes with their own API, way of implementing same things differently, and so on. I was thrilled by the presentations at Build 2018 [2] because they indicated that we can use a generic work-flow approach that allows us to evaluate the subject with local data, local .Net programs, local models, and results, without having to use a service or another programming language like Python.

Overview Machine learning is a subset of Artificial Intelligence (AI) and it can answer 5 types of questions [3]: Supervised 1. Classification (Binary and Multiclass) Question: What class does it belong to? 2. Regression Question: How much or how many?

Unsupervised 1. Ranking Question: What should I do next? 2. Clustering Question: How is this organized? 3. Anomaly Detection Question: Is this weird?

Each type of question has many applications and in order to use the correct machine learning approach we must first try to determine if we want to answer any of the given questions, and if so, whether we have the data to support it.

Supervised Machine Learning This article discusses working .Net examples (source code including sample data) for binary and multiclass classifications. This type of machine learning algorithm assumes that we can tag an item to determine whether it belongs to: 1. One of two groups (binary classification) or 2. One of many groups (multiclass classification) A binary classification can be applied when you want to answer a question with a true or false answer. You usually find yourself sorting an item (an image or text) into one of 2 classes. Consider, for instance, the question of whether a customer feedback to your recent survey is in a good mood (positive) or not (negative). Answering this question with machine learning requires us to tag sample items (eg: images or text) as belonging to either group. The normal work-flow requires two independent sets of tagged data: 1. A Training Data Set (to train the machine learning algorithm) and 2. An Evaluation Data Set (to measure the efficiency of the ml algorithm). A tagged line of text may look like this: 1 Grow up you biased child. 0 I hope this helps.  where "1" in the first column denotes a negative sentiment and "0" in the first column denotes a positive sentiment. The rule of thumb is usually that the ml algorithm will work better if we have more training data. And it should also be assured that the training data and the data used later on is clean and of high quality to support an effective algorithm. The overall work-flow to determine an effective algorithm using KPIs is denoted by the diagram on the left side below, where we (ideally) find a model model that  that reflects our classification problem best. The model is not explained in more detail here. It is, in the case of ML.Net, a zip file containing the persisted facts learned from the tagged training data.

htt https: ps://w //www ww.cod .codepr eproje oject. ct.com/ com/Art Article icles/1 s/1249 249611 611/Ma /Machi chinene-Lea Learn rning ing-wi -withth-ML ML-Ne -Net-a t-andnd-Csh Csharp arp--VBVB-Net Net?di ?displ splay= ay=Pr Print int

2/17 2/17

 

28/06/2018

Machine Learning with ML.Net and C#/VB.Net - CodeProject

The second independent data set for evaluation is used to determine KPIs towards the efficiency of the learned classification. This steps estimates how good our algorithm will classify items in the future by comparing the result from the machine learning algorithm  with the available tag (without using the tag in the algorithm). A KPI to measure efficiency is, for example, the percentage of the number of items classified right versus the wrong classified items. We can always go back to the training step, and adjust parameters, or swap one algorithm for the other, if we find that our KPIs do not meet our expectations and we need ways to optimize the model. The Training Training stage  stage hopefully ends with an effective model which can be applied in the second Prediction Prediction stage  stage to classify each item that we see in the future. This stage requires the model from the previous stage and the item to classify, which is used to output a prediction of a classification (eg.: positive or negative sentiment). This is a brief overview the work-flow attended learning. We need to understand this to work with the code samples discussed in this article on further below. So,for lets look at machine each sample in turn.

Binary Classification htt https: ps://w //www ww.cod .codepr eproje oject. ct.com/ com/Art Article icles/1 s/1249 249611 611/Ma /Machi chinene-Lea Learn rning ing-wi -withth-ML ML-Ne -Net-a t-andnd-Csh Csharp arp--VBVB-Net Net?di ?displ splay= ay=Pr Print int

3/17 3/17

 

28/06/2018

Machine Learning with ML.Net and C#/VB.Net - CodeProject

Sentiment Analysis Wikipedia The sample discussed in this section is based on A Sentiment Analysis Binary Classification Scenario from Scenario  from the ML.Net tutorial. Wikipedia_SentimentAnalysis.zip

Training Stage The work-flow discussed in the previous section is implemented to some degree in the demo projects attached to this article. The demo project contains two executable projects: Training and Prediction We get the following output if we compile and start the Training Training project:  project: Training Data Set ----------------Not adding a normalizer. Making per-feature arrays Changing data from from row-wise  row-wise to column-wise Processed 250 250 instances  instances Binning and forming Feature objects for tree  tree learner: 1943796 1943796 bytes  bytes Reserved memory for Starting to train ... Not training a calibrator because it is is not  not needed. Evaluating Training Results --------------------------PredictionModel quality metrics evaluation -----------------------------------------Accuracy: 61 61,11% ,11% Auc: 96 96,30% ,30% F1Score: 72 72,00% ,00% We see here how the program first trains a model and evaluates the result in the second step. The Training Training and  and the Prediction Prediction modul  modul share a reference to the previously mentioned Model.zip Model.zip file  file (most be copied manually see details below), a reference to ML.Net library, and a common model of the data input and the classification output defined in the Models project: public  public  class ClassificationData class ClassificationData { [Column(ordinal: "0" "0", , name: "Label" "Label")] )] public float public  float Sentiment;  Sentiment; "1")] )] [Column(ordinal: "1" public string public  string Text;  Text; } public   class ClassPrediction class ClassPrediction public { [ColumnName("PredictedLabel" [ColumnName( "PredictedLabel")] )] public  bool Class;  Class; public bool }

Public Public   Class ClassificationData Class ClassificationData "0", , "Label")> "Label")> )>
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF