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

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

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

UCI Machine Learning Repository: Iris Data Set下载一个现成的数据集,复制粘贴其中的数据到任何一个文本编辑器中,然后保存命名为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("")]
public float SepalLength; [Column("")]
public float SepalWidth; [Column("")]
public float PetalLength; [Column("")]
public float PetalWidth; [Column("")]
[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<IrisData>(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<IrisData, IrisPrediction>(); // 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}");
}
}
}

.NET Core玩转机器学习的更多相关文章

  1. .NET Core 玩一玩 Ocelot API网关

    .net 这几年国内确实不好过. 很多都选择转行.不过.net Core跨平台 开源之后 .社区的生态在慢慢建立.往好的趋势发展. 对于坚守在.NET战线的开发者来说 是个挺不错的消息.  特别是微软 ...

  2. 使用ML.NET实现猜动画片台词

    前面几篇主要内容出自微软官方,经我特意修改的案例的文章: 使用ML.NET实现情感分析[新手篇] 使用ML.NET预测纽约出租车费 .NET Core玩转机器学习 使用ML.NET实现情感分析[新手篇 ...

  3. 使用ML.NET实现情感分析[新手篇]

    在发出<.NET Core玩转机器学习>和<使用ML.NET预测纽约出租车费>两文后,相信读者朋友们即使在不明就里的情况下,也能按照内容顺利跑完代码运行出结果,对使用.NET ...

  4. 使用ML.NET预测纽约出租车费

    有了上一篇<.NET Core玩转机器学习>打基础,这一次我们以纽约出租车费的预测做为新的场景案例,来体验一下回归模型. 场景概述 我们的目标是预测纽约的出租车费,乍一看似乎仅仅取决于行程 ...

  5. ML.NET

    ML.NET http://www.cnblogs.com/BeanHsiang/category/1218714.html 随笔分类 - 使用ML.NET实现NBA得分预测 摘要: 本文将介绍一种特 ...

  6. .NET Core开发者的福音之玩转Redis的又一傻瓜式神器推荐

    作者:依乐祝 原本链接:https://www.cnblogs.com/yilezhu/p/9947905.html 引子 为什么写这篇文章呢?因为.NET Core的生态越来越好了!之前玩转.net ...

  7. [翻译] C# 8.0 新特性 Redis基本使用及百亿数据量中的使用技巧分享(附视频地址及观看指南) 【由浅至深】redis 实现发布订阅的几种方式 .NET Core开发者的福音之玩转Redis的又一傻瓜式神器推荐

    [翻译] C# 8.0 新特性 2018-11-13 17:04 by Rwing, 1179 阅读, 24 评论, 收藏, 编辑 原文: Building C# 8.0[译注:原文主标题如此,但内容 ...

  8. 玩转docker

    开篇先论赌 (组词,赌博,....),时刻,每天都在赌! 何为赌?仁者见仁,智者必定又有一番见解,保持沉默,意见保留; ——改变思维模式,Ruiy让赌赢在“思维”!!!; 存在在IT界Ruiy定格,即 ...

  9. .NET Core容器化@Docker

    温馨提示:本文适合动手演练,效果更佳.  1. 引言 我们知道. NET Core最大的特性之一就是跨平台,而对于跨平台,似乎大家印象中就是可以在非Windows系统上部署运行.而至于如何操作,可能就 ...

随机推荐

  1. gulp 粗粗学习 记录下

    看视频学习 粗粗记录下 以便以后学习 1.初记录 gulp.task //定义一个任务 gulp.src //锁定到做task任务的文件路径 gulp.dest //锁定到任务做完后文件去向的路径 g ...

  2. UOJ#104. 【APIO2014】Split the sequence 动态规划 斜率优化

    原文链接www.cnblogs.com/zhouzhendong/p/UOJ104.html 题解 首先证明一个结论:对于一种分割方案,分割的顺序不影响最终结果. 证明:对于树 a[x] 和 a[y] ...

  3. 使用Tornado异步接入第三方(支付宝)支付

    目前国内比较流行的第三方支付主要有支付宝和微信支付,博主最近研究了下如何用Python接入支付宝支付,这里我以Tornado作为web框架,接入支付宝构造支付接口. 使用Tornado异步接入支付宝支 ...

  4. maya cmds pymel selectType() 选择类型切换

    maya cmds pymel selectType() 选择类型切换 import maya.cmds as cmds cmds.selectType( polymeshFace = True ) ...

  5. C++结构体与Delphi结构体相互传参,结构体中包含结构体的嵌套,数组指针

    //结构体的声明 typedef struct Mwinddirectbaseline { char* p; int s; int i; }Mwinddirectbaseline; typedef s ...

  6. 1.3 正则表达式和python语言-1.3.7 匹配任何单个字符

    1.3.7 匹配任何单个字符 (2018-05-08) 点号(.)不能匹配一个换行符\n 或者非字符,也就是说,一个空字符串 搜索一个真正的句点(小数点), 而我们通过使用一个反斜线对句点的功能进行转 ...

  7. HTTP协议头部与Keep-Alive模式详解(转)

    转自:http://a280606790.iteye.com/blog/1095085 http1.1 中怎么打开持久连接,怎么关闭,怎么传输数据(确定本次数据是否传输完毕) 1.什么是Keep-Al ...

  8. vbs脚本实现qq定时发消息(初级)

    vbs脚本实现QQ消息定时发送 目标 批处理又称为批处理脚本,强大的强大功能可以高效得实现很多功能,例如批量更改文件格式,批量进行文件读写,今天我们的目标是用vbs脚本编写可以发送qq消息的脚本,并利 ...

  9. Mysql初学入门

    最近研究了一下Mysql的初学应用,在此进行整理记录. 1.Windows系统下的安装 我用的是win10系统,在http://dev.mysql.com/downloads/mysql/ 下载相应版 ...

  10. Spring源码学习相关记录

    Spring单例实现: protected Object getSingleton(String beanName, boolean allowEarlyReference) { Object sin ...