1

I am trying to run following code:

// 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); 
        } 
    } 
} 

However, it is giving following error:

$ 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.

I am working on Debian Stable Linux with mono-complete installed.

How can this error be corrected? Thanks for your help.

Edit: On modifying the code as suggested in comments:

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); 
    } 
}

I get following error:

$ 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
rnso
  • 23,686
  • 25
  • 112
  • 234
  • 1
    Usings have to be at the top of the file. Where did you get this code from? I couldn't find it in the source you provided. Try putting `using Accord.Statistics.Models.Regression.Linear;` below `using System;` rather than inside the namespace – Mravec Jun 08 '19 at 12:23
  • 1
    `using` directives always go at the top of the file, outside of any `namespace` declarations or anything. This has nothing to do with Accord or Debian or Mono, it's just the C# language. – David Jun 08 '19 at 12:26
  • @pravymravec : Part of code is from link provided. On putting `using` above as suggested leads to `error CS0246: The type or namespace name `Accord' could not be found. Are you missing an assembly reference?` Pl see edit in my question above. – rnso Jun 08 '19 at 12:55
  • 1
    @rnso: You're compiling just a `.cs` file, not an entire project, so currently there are no references to external assemblies. I don't know if `mono-csc` has the same format for command-line arguments, but take a look at the command-line compilation being done here: https://stackoverflow.com/questions/10722832/csc-exe-reference-external-dll-file Note how `.dll` files are being specified during compilation. You'll need to include yours as well. – David Jun 08 '19 at 12:59
  • In another question `mcs gtkexample2.cs -pkg:gtk-sharp-2.0` worked. But here `$ mono-csc linreg.cs -pkg:Accord.Statistics.Models.Regression.Linear` is not working. The error is: `No package 'Accord.Statistics.Models.Regression.Linear' found` – rnso Jun 08 '19 at 13:24

0 Answers0