博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.NET Core玩转机器学习
阅读量:7088 次
发布时间:2019-06-28

本文共 3220 字,大约阅读时间需要 10 分钟。

最近在搞机器学习,目前国内没有什么关于ML.NET的教程,官方都是一大堆英文,经过了我的努力,找到了大哥的博客,有关于ML.NET的内容

原文地址:https://www.cnblogs.com/BeanHsiang/p/9010267.html  

使用ML.NET直接从nuget中搜索ML.NET 安装到项目即可

去下载一个现成的数据集,复制粘贴其中的数据到任何一个文本编辑器中,然后保存命名为iris-data.txt到myApp目录中。

打开program.cs 以下代码:

using Microsoft.ML;using Microsoft.ML.Runtime.Api;using Microsoft.ML.Trainers;using Microsoft.ML.Transforms;using System;namespace myApp{    class Program    {        // STEP 1: Define your data structures        // IrisData is used to provide training data, and as         // input for prediction operations        // - First 4 properties are inputs/features used to predict the label        // - Label is what you are predicting, and is only set when training        public class IrisData        {            [Column("0")]            public float SepalLength;            [Column("1")]            public float SepalWidth;            [Column("2")]            public float PetalLength;            [Column("3")]            public float PetalWidth;            [Column("4")]            [ColumnName("Label")]            public string Label;        }        // IrisPrediction is the result returned from prediction operations        public class IrisPrediction        {            [ColumnName("PredictedLabel")]            public string PredictedLabels;        }        static void Main(string[] args)        {            // STEP 2: Create a pipeline and load your data            var pipeline = new LearningPipeline();            // If working in Visual Studio, make sure the 'Copy to Output Directory'             // property of iris-data.txt is set to 'Copy always'            string dataPath = "iris-data.txt";            pipeline.Add(new TextLoader
(dataPath, separator: ",")); // STEP 3: Transform your data // Assign numeric values to text in the "Label" column, because only // numbers can be processed during model training pipeline.Add(new Dictionarizer("Label")); // Puts all features into a vector pipeline.Add(new ColumnConcatenator("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); // STEP 4: Add learner // Add a learning algorithm to the pipeline. // This is a classification scenario (What type of iris is this?) pipeline.Add(new StochasticDualCoordinateAscentClassifier()); // Convert the Label back into original text (after converting to number in step 3) pipeline.Add(new PredictedLabelColumnOriginalValueConverter() { PredictedLabelColumn = "PredictedLabel" }); // STEP 5: Train your model based on the data set var model = pipeline.Train
(); // STEP 6: Use your model to make a prediction // You can change these numbers to test different predictions var prediction = model.Predict(new IrisData() { SepalLength = 3.3f, SepalWidth = 1.6f, PetalLength = 0.2f, PetalWidth = 5.1f, }); Console.WriteLine($"Predicted flower type is: {prediction.PredictedLabels}"); } }}

 

转载于:https://www.cnblogs.com/ZaraNet/p/9847950.html

你可能感兴趣的文章
8月8日小记
查看>>
u-boot中环境变量的实现
查看>>
Android开发之Button事件实现方法的总结
查看>>
Squid调试和故障处理
查看>>
MIME protocol 说明
查看>>
Google LOGO现代舞舞蹈动画
查看>>
<context:component-scan>配置解析(转)
查看>>
poj 2041 Unreliable Message 字符串处理
查看>>
有人3见解
查看>>
[python]decimal常用操作和需要注意的地方
查看>>
Ubuntu 网卡信息2
查看>>
android 没有main函数,怎么找到程序执行入口呢?以及activity主要生命周期的方法说明...
查看>>
java中处理字符编码(网页与数据库)(转)
查看>>
[leetcode]Path Sum II
查看>>
BZOJ 1806 IOI2007 Miners 矿工配餐 动态规划
查看>>
参考例子,学习Func<T, TResult>委托
查看>>
NTFS For Mac 如何简单操作
查看>>
django 生成复杂的 PDF 文件(数据较多时)
查看>>
CodeForces 300C 最短路
查看>>
睡觉被憋醒
查看>>