曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
C#

试一下用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

曦远 (DealiAxy)约 5 分钟
目录7 个章节

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百科上面的用户评论数据,请自行下载

https://raw.githubusercontent.com/dotnet/machinelearning/master/test/data/wikipedia-detox-250-line-data.tsv

下载之后命名为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; }
    }
}

挖个坑

先挖个坑,明天继续研究。

参考资料

_EOF_

试一下用DotNetCore来做机器学习,ML-Net框架跑起来

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

C#学习(二)匿名方法和委托的多种使用方式

前言 上次简单介绍了委托的概念和使用,今天继续,并且引入匿名方法的概念,匿名方法在很多语言里面都有,比如Python、js、java8,尤其js,前端小伙伴可能深受js回调地狱之苦,这里面匿名方法功不可没。 js的匿名方法就像这样: 这还没用lambda,因为我想下篇再介绍lambda。 document.querySelector('.btn').onclick = function () {

2021-12-18 · C# · 约 1 分钟

C#学习(一)委托的概念和使用

前言 C#学习系列是根据我以前的笔记整理出来复习,顺便发一下文章做个记录。 先引用一个介绍: C# 中的委托(Delegate)类似于 C 或 C++ 中函数的指针。委托(Delegate) 是存有对某个方法的引用的一种引用类型变量。引用可在运行时被改变。 委托(Delegate)特别用于实现事件和回调方法。所有的委托(Delegate)都派生自 System.Delegate 类。 根据使用其他

2021-12-18 · C# · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…