ML03 利用Accord 进行机器学习的第一个小例子

01 安装 Visual studio 2017.

 不具备安装这个的话,也可安装,Microsoft Visual Studio Express (or equivalent)

 

02 创建 C# 的 控制台程序

 

03 添加 Accord 库

 

 03  让机器学习『异或』的逻辑

不需要在代码里写出来异或的程序逻辑,告诉机器 异或的输入和输出(其实就是一个监督学习,训练的过程),机器就自己学习会了异或逻辑。

上代码:

 1 using System;
 2 using Accord.Controls;
 3 using Accord.MachineLearning.VectorMachines;
 4 using Accord.MachineLearning.VectorMachines.Learning;
 5 using Accord.Math;
 6 using Accord.Statistics.Kernels;
 7 using Accord.Math.Optimization.Losses;
 8 using Accord.Statistics;
 9 
10 namespace SampleApplication1
11 {
12     class Program
13     {
14         [MTAThread]
15         static void Main(string[] args)
16         {
17             double[][] inputs =
18             {
19                 /* 1.*/ new double[] { 0, 0 },
20                 /* 2.*/ new double[] { 1, 0 }, 
21                 /* 3.*/ new double[] { 0, 1 }, 
22                 /* 4.*/ new double[] { 1, 1 },
23             };
24 
25             int[] outputs =
26             { 
27                 /* 1. 0 xor 0 = 0: */ 0,
28                 /* 2. 1 xor 0 = 1: */ 1,
29                 /* 3. 0 xor 1 = 1: */ 1,
30                 /* 4. 1 xor 1 = 0: */ 0,
31             };
32 
33             // Create the learning algorithm with the chosen kernel
34             var smo = new SequentialMinimalOptimization<Gaussian>()
35             {
36                 Complexity = 100 // Create a hard-margin SVM 
37             };
38 
39             // Use the algorithm to learn the svm
40             var svm = smo.Learn(inputs, outputs);
41 
42             // Compute the machine's answers for the given inputs
43             bool[] prediction = svm.Decide(inputs);
44 
45             // Compute the classification error between the expected 
46             // values and the values actually predicted by the machine:
47             double error = new AccuracyLoss(outputs).Loss(prediction);
48 
49             Console.WriteLine("Error: " + error);
50 
51             // Show results on screen 
52             ScatterplotBox.Show("Training data", inputs, outputs);
53             ScatterplotBox.Show("SVM results", inputs, prediction.ToZeroOne());
54 
55             Console.ReadKey();
56         }
57     }
58 }

 

04  运行搞定

 

 本文的源代码:

 链接:https://pan.baidu.com/s/1gfrQyPX 

密码: 关注微信输入关键字: 异或

 

转载于:https://www.cnblogs.com/zhixingheyi/p/8111439.html

Power your C# and .NET applications with exciting machine learning models and modular projects Key Features Produce classification, regression, association, and clustering models Expand your understanding of machine learning and C# Get to grips with C# packages such as Accord.net, LiveCharts, and Deedle Book Description Machine learning is applied in almost all kinds of real-world surroundings and industries, right from medicine to advertising; from finance to scientifc research. This book will help you learn how to choose a model for your problem, how to evaluate the performance of your models, and how you can use C# to build machine learning models for your future projects. You will get an overview of the machine learning systems and how you, as a C# and .NET developer, can apply your existing knowledge to the wide gamut of intelligent applications, all through a project-based approach. You will start by setting up your C# environment for machine learning with the required packages, Accord.NET, LiveCharts, and Deedle. We will then take you right from building classifcation models for spam email fltering and applying NLP techniques to Twitter sentiment analysis, to time-series and regression analysis for forecasting foreign exchange rates and house prices, as well as drawing insights on customer segments in e-commerce. You will then build a recommendation model for music genre recommendation and an image recognition model for handwritten digits. Lastly, you will learn how to detect anomalies in network and credit card transaction data for cyber attack and credit card fraud detections. By the end of this book, you will be putting your skills in practice and implementing your machine learning knowledge in real projects. What you will learn Set up the C# environment for machine learning with required packages Build classification models for spam email filtering Get to grips with feature engineering using NLP techniques for Twitter sentiment analysis Forecast foreign exchange rates using continuous and time-series data Make a recommendation model for music genre recommendation Familiarize yourself with munging image data and Neural Network models for handwritten-digit recognition Use Principal Component Analysis (PCA) for cyber attack detection One-Class Support Vector Machine for credit card fraud detection Who this book is for If you're a C# or .NET developer with good knowledge of C#, then this book is perfect for you to get Machine Learning into your projects and make smarter applications. Table of Contents Basics of machine learning modeling Spam email filtering Twitter sentiment analysis Foreign exchange rate forecast Fair value of house/property Customer segmentation Music genre recommendation Handwritten digit recognition Cyber attack detection Credit card fraud detection What is next?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值