private static PartialLeastSquaresAnalysis CreateWineExample_new_method(out double[][] inputs, out double[][] outputs)
{
#region doc_learn
// References: http://www.utdallas.edu/~herve/Abdi-PLSR2007-pretty.pdf
// Following the small example by Hervé Abdi (Hervé Abdi, Partial Least Square Regression),
// we will create a simple example where the goal is to predict the subjective evaluation of
// a set of 5 wines. The dependent variables that we want to predict for each wine are its
// likeability, and how well it goes with meat, or dessert (as rated by a panel of experts).
// The predictors are the price, the sugar, alcohol, and acidity content of each wine.
// Here we will list the inputs, or characteristics we would like to use in order to infer
// information from our wines. Each row denotes a different wine and lists its corresponding
// observable characteristics. The inputs are usually denoted by X in the literature.
inputs = new double[][]
{
// Wine | Price | Sugar | Alcohol | Acidity
new double[] { 7, 7, 13, 7 },
new double[] { 4, 3, 14, 7 },
new double[] { 10, 5, 12, 5 },
new double[] { 16, 7, 11, 3 },
new double[] { 13, 3, 10, 3 },
};
// Here we will list our dependent variables. Dependent variables are the outputs, or what we
// would like to infer or predict from our available data, given a new observation. The outputs
// are usually denotes as Y in the literature.
outputs = new double[][]
{
// Wine | Hedonic | Goes with meat | Goes with dessert
new double[] { 14, 7, 8 },
new double[] { 10, 7, 6 },
new double[] { 8, 5, 5 },
new double[] { 2, 4, 7 },
new double[] { 6, 2, 4 },
};
// Next, we will create our Partial Least Squares Analysis passing the inputs (values for
// predictor variables) and the associated outputs (values for dependent variables).
// We will also be using the using the Covariance Matrix/Center method (data will only
// be mean centered but not normalized) and the NIPALS algorithm.
var pls = new PartialLeastSquaresAnalysis()
{
Method = AnalysisMethod.Center,
Algorithm = PartialLeastSquaresAlgorithm.SIMPLS
};
// Compute the analysis with all factors. The number of factors
// could also have been specified in a overload of this method.
var regression = pls.Learn(inputs, outputs);
// After the regression has been created, we will be able to classify new instances.
// For example, we will compute the outputs for the first input sample:
double[] y = regression.Transform(new double[] { 7, 7, 13, 7 });
// The y output will be very close to the corresponding output used as reference.
// In this case, y is a vector of length 3 with values { 14.00, 7.00, 7.75 }.
#endregion
Assert.AreEqual(14.00, y[0], 1e-2);
Assert.AreEqual(+7.00, y[1], 1e-2);
Assert.AreEqual(+7.75, y[2], 1e-2);
return pls;
}