numl.net 机器学习(一):预测是否迟到
从nuget上搜索numl并安装.我们主要从两个参数(星期几和温度,对于一般的人来说周一容易迟到,天太冷容易迟到)来预测是否迟到,
demo代码如下:
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- WorkTime[] data = WorkTime.GetData();
- var d = Descriptor.Create<WorkTime>();
- var g = new DecisionTreeGenerator(d);
- g.SetHint(false);
- var model = Learner.Learn(data, 0.80, 1000, g);
- WorkTime t = new WorkTime
- {
- ComeTime = DateTime.Parse("2018-05-21"),
- Temp =40
- };
- WorkTime result = model.Model.Predict(t);
- Console.Write(result.IsLate);
- Console.Read();
- }
- }
- //Feature 参考的参数,Label为结果
- public class WorkTime
- {
- public DateTime ComeTime { get; set; }//上班日期
- [Feature]
- public int WorkDay//星期几
- {
- get
- {
- return (int)ComeTime.DayOfWeek;
- }
- }
- [Feature]
- public int Temp { get; set; }//温度
- [Label]
- public bool IsLate { get; set; }
- public static WorkTime[] GetData()
- {
- return new WorkTime[] {
- new WorkTime { ComeTime=DateTime.Parse("2018-02-01") , Temp=12, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-02-02") , Temp=9, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-02-05") , Temp=22, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-02-06") , Temp=22, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-02-07") , Temp=28, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-02-08") , Temp=7, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-02-09") , Temp=28, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-02-12") , Temp=22, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-01") , Temp=22, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-02") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-05") , Temp=26, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-06") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-07") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-08") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-09") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-12") , Temp=26, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-13") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-14") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-15") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-16") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-19") , Temp=26, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-20") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-21") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-22") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-23") , Temp=26, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-26") , Temp=33, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-27") , Temp=12, IsLate=true },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-28") , Temp=31, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-29") , Temp=32, IsLate=false },
- new WorkTime { ComeTime=DateTime.Parse("2018-03-30") , Temp=28, IsLate=false },
- //
- //
- //new WorkTime { ComeTime=DateTime.Parse("2018-04-02") , Temp=28, IsLate=true },
- //new WorkTime { ComeTime=DateTime.Parse("2018-04-09") , Temp=8, IsLate=true },
- //new WorkTime { ComeTime=DateTime.Parse("2018-04-16") , Temp=12, IsLate=true },
- //new WorkTime { ComeTime=DateTime.Parse("2018-04-23") , Temp=6, IsLate=true },
- //new WorkTime { ComeTime=DateTime.Parse("2018-04-30") , Temp=38, IsLate=true },
- //new WorkTime { ComeTime=DateTime.Parse("2018-05-07") , Temp=24, IsLate=true },
- //new WorkTime { ComeTime=DateTime.Parse("2018-05-14") , Temp=18, IsLate=true },
- };
- }
- }
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · 监督学习(supervised learning)和非监督学习(unsupervised learning)
- · The instance of entity type ‘Customer’ cannot be tracked because another instance with the same key value for {‘Id’} is already being tracked.
- · .NET8实时更新nginx ip地址归属地
- · 解决.NET Blazor子组件不刷新问题
- · .NET8如何在普通类库中引用 Microsoft.AspNetCore
- · .NET8 Mysql SSL error
- · ASP.NET Core MVC的Razor视图渲染中文乱码的问题
- · .NETCORE 依赖注入服务生命周期
- · asp.net zero改mysql
- · .NET5面试汇总
- · .Net连接Mysql数据库的Convert Zero Datetime日期问题
- · vue使用element-ui中的Message 、MessageBox 、Notification