试一下用DotNetCore来做机器学习,ML Net框架跑起来
ML.Net简介
官网:https://dotnet.microsoft.com/apps/machinelearning-ai/ml-dotnet
官方介绍:The ML.NET command line interface (CLI), provides tools for building machine learning models with ML.NET.
ML.NET 是面向.NET开发人员的开源和跨平台机器学习框架。 ML.NET 还包括Model Builder (一个简单的UI工具)和 CLI ,使用自动机器学习(AutoML)构建自定义机器学习(ML)模型变得非常容易。
首先安装.NetCore,这个是必备的~
安装ML.Net
dotnet tool install -g mlnet
下载训练集
下面这个而是wiki百科上面的用户评论数据,请自行下载
下载之后命名为wikipedia-data.tsv
~
训练模型
mlnet auto-train --task binary-classification --dataset "wikipedia-data.tsv" --label-column-index 0 --has-header true --max-exploration-time 10
训练成功会显示结果,如下:
并且会在目录下生成代码
模型代码
我们来看看ML.Net自动生成的模型代码:
ModelInput.cs
using Microsoft.ML.Data;
namespace SampleBinaryClassification.Model.DataModels
{
public class ModelInput
{
[ColumnName("Sentiment"), LoadColumn(0)]
public bool Sentiment { get; set; }
[ColumnName("SentimentText"), LoadColumn(1)]
public string SentimentText { get; set; }
}
}
ModelOutput.cs
using System;
using Microsoft.ML.Data;
namespace SampleBinaryClassification.Model.DataModels
{
public class ModelOutput
{
// ColumnName attribute is used to change the column name from
// its default value, which is the name of the field.
[ColumnName("PredictedLabel")]
public bool Prediction { get; set; }
public float Score { get; set; }
}
}
挖个坑
先挖个坑,明天继续研究。