分享

C# 机器学习实战SVM多分类

 吴敬锐 2023-09-14

1:先用一下  Accord.MachineLearning(在NuGet下载即可)

2:引用

using Accord.MachineLearning.VectorMachines.Learning;
using Accord.Statistics.Kernels;

3:实例SVM多分类

Code:

double[][] inputs =
            {
                new double[] { 0 },
                new double[] { 3 },
                new double[] { 1 },
                new double[] { 2 },
            };
            double[][] inputsTest =
            {
                new double[] { 4 },
            };

            // Outputs for each of the inputs
            int[] outputs =
            {
                0,
                3,
                1,
                2,
            };
            // Create the Multi-label learning algorithm for the machine
            var teacher = new MulticlassSupportVectorLearning<Linear>()
            {
                Learner = (p) => new SequentialMinimalOptimization<Linear>()
                {
                    Complexity = 10000.0 // Create a hard SVM
                }
            };
            // Learn a multi-label SVM using the teacher
            var svm = teacher.Learn(inputs, outputs);
            // Compute the machine answers for the inputs
            int[] answers = svm.Decide(inputsTest);
            Console.WriteLine(answers[0]);
            Console.ReadKey();

github网址:    https://github.com/accord-net/framework/wiki/Classification


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多