在哪里放置“名称空间”和“使用”以进行Accord机器学习

时间:2019-06-08 12:21:03

标签: c# namespaces mono accord.net

我正在尝试运行以下代码:

// modified from: https://github.com/accord-net/framework/wiki/Regression 

using System;

namespace Accord.Statistics {
    using Accord.Statistics.Models.Regression.Linear; 

    class Program {
        // Declare some sample test data.
        double[] inputs = { 80, 60, 10, 20, 30 };
        double[] outputs = { 20, 40, 30, 50, 60 };
        // Use Ordinary Least Squares to learn the regression
        OrdinaryLeastSquares ols = new OrdinaryLeastSquares();
        SimpleLinearRegression regression = ols.Learn(inputs, outputs);
        // Compute the output for a given input:
        double y = regression.Transform(85); // The answer will be 28.088
        // We can also extract the slope and the intercept term
        // for the line. Those will be -0.26 and 50.5, respectively.
        double s = regression.Slope;     // -0.264706
        double c = regression.Intercept; // 50.588235

        static void Main(string[] args) {
            Console.WriteLine("Linear regression test; slope: {0:D} intercept:{1:D}; Predicted:{3:D}.", s, c, y); 
        } 
    } 
} 

但是,它给出了以下错误:

$ mcs linreg.cs -pkg:Accord.Statistics.Models.Regression.Linear
Package Accord.Statistics.Models.Regression.Linear was not found in the pkg-config search path.
Perhaps you should add the directory containing `Accord.Statistics.Models.Regression.Linear.pc'
to the PKG_CONFIG_PATH environment variable
No package 'Accord.Statistics.Models.Regression.Linear' found
error CS8027: Error running pkg-config. Check the above output.

我正在安装单完成的Debian Stable Linux。

如何纠正此错误?感谢您的帮助。

编辑:按照注释中的建议修改代码:

using System;
using Accord.Statistics.Models.Regression.Linear; 
class Program {
    // Declare some sample test data.
    double[] inputs = { 80, 60, 10, 20, 30 };
    double[] outputs = { 20, 40, 30, 50, 60 };
    // Use Ordinary Least Squares to learn the regression
    OrdinaryLeastSquares ols = new OrdinaryLeastSquares();
    SimpleLinearRegression regression = ols.Learn(inputs, outputs);
    // Compute the output for a given input:
    double y = regression.Transform(85); // The answer will be 28.088
    // We can also extract the slope and the intercept term
    // for the line. Those will be -0.26 and 50.5, respectively.
    double s = regression.Slope;     // -0.264706
    double c = regression.Intercept; // 50.588235

    static void Main(string[] args) {
        Console.WriteLine("Linear regression test; slope: {0:D} intercept:{1:D}; Predicted:{3:D}.", s, c, y); 
    } 
}

我收到以下错误:

$ mono-csc linreg.cs 
linreg.cs(5,7): error CS0246: The type or namespace name `Accord' could not be found. Are you missing an assembly reference?
linreg.cs(12,3): error CS0246: The type or namespace name `OrdinaryLeastSquares' could not be found. Are you missing an assembly reference?
linreg.cs(13,3): error CS0246: The type or namespace name `SimpleLinearRegression' could not be found. Are you missing an assembly reference?
Compilation failed: 3 error(s), 0 warnings

0 个答案:

没有答案