Click or drag to resize
Accord.NET (logo)

MultivariateLinearRegression Class

Multivariate Linear Regression.
Inheritance Hierarchy
SystemObject
  Accord.MachineLearningTransformBaseDouble, Double
    Accord.MachineLearningMultipleTransformBaseDouble, Double
      Accord.Statistics.Models.Regression.LinearMultivariateLinearRegression

Namespace:  Accord.Statistics.Models.Regression.Linear
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class MultivariateLinearRegression : MultipleTransformBase<double[], double>, 
	ILinearRegression
Request Example View Source

The MultivariateLinearRegression type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCoefficients Obsolete.
Gets the coefficient matrix used by the regression model. Each column corresponds to the coefficient vector for each of the outputs.
Public propertyInputs Obsolete.
Gets the number of inputs in the model.
Public propertyIntercepts
Gets the intercept vector (bias).
Public propertyNumberOfInputs
Gets the number of inputs accepted by the model.
(Inherited from TransformBaseTInput, TOutput.)
Public propertyNumberOfOutputs
Gets the number of outputs generated by the model.
(Inherited from TransformBaseTInput, TOutput.)
Public propertyNumberOfParameters
Gets the number of parameters in the model (returns NumberOfInputs * NumberOfOutputs + NumberOfInputs).
Public propertyOutputs Obsolete.
Gets the number of outputs in the model.
Public propertyWeights
Gets the linear weights matrix.
Top
Methods
  NameDescription
Public methodCoefficientOfDetermination(Double, Double, Double)
Gets the coefficient of determination, as known as R² (r-squared).
Public methodCoefficientOfDetermination(Double, Double, Boolean, Double)
Gets the coefficient of determination, as known as R² (r-squared).
Public methodCompute(Double) Obsolete.
Computes the Multiple Linear Regression output for a given input.
Public methodCompute(Double) Obsolete.
Computes the Multiple Linear Regression output for a given input.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodStatic memberFromCoefficients Obsolete.
Creates a new linear regression from the regression coefficients.
Public methodStatic memberFromData
Creates a new linear regression directly from data points.
Public methodGetConfidenceInterval
Gets the confidence interval for an input point.
Public methodGetDegreesOfFreedom
Gets the degrees of freedom when fitting the regression.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetPredictionInterval
Gets the prediction interval for an input point.
Public methodGetPredictionStandardError
Gets the standard error of the prediction for a particular input vector.
Public methodGetStandardError(Double, Double)
Gets the overall regression standard error.
Public methodGetStandardError(Double, Double, Double)
Gets the standard error of the fit for a particular input vector.
Public methodGetStandardErrors
Gets the standard error for each coefficient.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInverse
Creates the inverse regression, a regression that can recover the input data given the outputs of this current regression.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRegress Obsolete.
Performs the regression using the input vectors and output vectors, returning the sum of squared errors of the fit.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTransform(TInput)
Applies the transformation to an input, producing an associated output.
(Inherited from MultipleTransformBaseTInput, TOutput.)
Public methodTransform(TInput)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from MultipleTransformBaseTInput, TOutput.)
Public methodTransform(TInput, TOutput)
Applies the transformation to an input, producing an associated output.
(Inherited from MultipleTransformBaseTInput, TOutput.)
Public methodTransform(Double, Double)
Applies the transformation to an input, producing an associated output.
(Overrides MultipleTransformBaseTInput, TOutputTransform(TInput, TOutput).)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks
Multivariate Linear Regression is a generalization of Multiple Linear Regression to allow for multiple outputs.
Examples
// The multivariate linear regression is a generalization of
// the multiple linear regression. In the multivariate linear
// regression, not only the input variables are multivariate,
// but also are the output dependent variables.

// In the following example, we will perform a regression of
// a 2-dimensional output variable over a 3-dimensional input
// variable.

double[][] inputs =
{
    // variables:  x1  x2  x3
    new double[] {  1,  1,  1 }, // input sample 1
    new double[] {  2,  1,  1 }, // input sample 2
    new double[] {  3,  1,  1 }, // input sample 3
};

double[][] outputs =
{
    // variables:  y1  y2
    new double[] {  2,  3 }, // corresponding output to sample 1
    new double[] {  4,  6 }, // corresponding output to sample 2
    new double[] {  6,  9 }, // corresponding output to sample 3
};

// With a quick eye inspection, it is possible to see that
// the first output variable y1 is always the double of the
// first input variable. The second output variable y2 is
// always the triple of the first input variable. The other
// input variables are unused. Nevertheless, we will fit a
// multivariate regression model and confirm the validity
// of our impressions:

// Use Ordinary Least Squares to create the regression
OrdinaryLeastSquares ols = new OrdinaryLeastSquares();

// Now, compute the multivariate linear regression:
MultivariateLinearRegression regression = ols.Learn(inputs, outputs);

// We can obtain predictions using
double[][] predictions = regression.Transform(inputs);

// The prediction error is
double error = new SquareLoss(outputs).Loss(predictions); // 0

// At this point, the regression error will be 0 (the fit was
// perfect). The regression coefficients for the first input
// and first output variables will be 2. The coefficient for
// the first input and second output variables will be 3. All
// others will be 0.
// 
// regression.Coefficients should be the matrix given by
// 
// double[,] coefficients = {
//                              { 2, 3 },
//                              { 0, 0 },
//                              { 0, 0 },
//                          };
// 

// We can also check the r-squared coefficients of determination:
double[] r2 = regression.CoefficientOfDetermination(inputs, outputs);
See Also