Im a student & new to C#
Could you help me to solve this problem?
I’ve to use LeastSquares regression or LSSVR and the Gaussian kernel.
There was an “Exception Unhandeld” occurd in my program while running it : System.NullReferenceException , Object reference not set to an instance of an object; It means that in the line where you use the support vector machine, the machine is not initialized correctly and an attempt is made to access a null object.
So I just checked and the result that appears in consule is:
“The machine has not been trained properly.”
But why? How can I fix this and train my machine properly?
my code:
`using Accord.MachineLearning.VectorMachines;
using Accord.MachineLearning.VectorMachines.Learning;
using Accord.Statistics.Kernels;
using System;
namespace machinlearningtest1
{
class Program
{
static void Main(string[] args)
{
// train dataset
double[][] inputs =
{
new double[] {1},
new double[] {0.9},
new double[] {1.1},
new double[] {1.2},
new double[] {1.3},
new double[] {1.01},
new double[] {0.8},
new double[] {0.99},
new double[] {1},
new double[] {1.2},
new double[] {1.3},
new double[] {1.4},
new double[] {1.5},
new double[] {1.6},
new double[] {1},
new double[] {4.75},
new double[] {5.5},
new double[] {4.9},
new double[] {4.7},
new double[] {5},
new double[] {4.4},
new double[] {5.5},
new double[] {5.4},
new double[] {5.3},
new double[] {5.2},
new double[] {5.1},
new double[] {4.9},
new double[] {4.8},
new double[] {4.5},
new double[] {5},
};
// 0 means -
// 1 means +
int[] outputs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
// kernel
var kernel = new Gaussian();
// Gaussian kernel
var machine = new SupportVectorMachine<Gaussian>(inputs: 1, kernel: kernel);
// Least Squares
var teacher = new LeastSquaresLearning<Gaussian, double[]>
{
Complexity = 10 // no overfitting
};
// train
teacher.Learn(inputs, outputs);
// check
if (machine.SupportVectors == null || machine.SupportVectors.Length == 0)
{
Console.WriteLine("The machine has not been trained properly.");
}
else
{
//test
double predicted = machine.Score(new double[] { 1.5 });
Console.WriteLine("Predicted score: " + predicted);
}
}
}
}
`
1