Click or drag to resize
Accord.NET (logo) MultipleLinearRegression Class
Multiple Linear Regression.
Inheritance Hierarchy
SystemObject
  Accord.MachineLearningTransformBaseDouble, Double
    Accord.Statistics.Models.Regression.LinearMultipleLinearRegression

Namespace:  Accord.Statistics.Models.Regression.Linear
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.4.0
Syntax
[SerializableAttribute]
public class MultipleLinearRegression : TransformBase<double[], double>, 
	ILinearRegression, IFormattable, ICloneable
Request Example View Source

The MultipleLinearRegression type exposes the following members.

Constructors
  NameDescription
Public methodMultipleLinearRegression
Initializes a new instance of the MultipleLinearRegression class.
Public methodMultipleLinearRegression(Int32) Obsolete.
Creates a new Multiple Linear Regression.
Public methodMultipleLinearRegression(Int32, Boolean) Obsolete.
Creates a new Multiple Linear Regression.
Public methodMultipleLinearRegression(Int32, Double) Obsolete.
Creates a new Multiple Linear Regression.
Top
Properties
  NameDescription
Public propertyCoefficients Obsolete.
Gets the coefficients used by the regression model. If the model contains an intercept term, it will be in the end of the vector.
Public propertyHasIntercept Obsolete.
Gets whether this model has an additional intercept term.
Public propertyInputs Obsolete.
Gets the number of inputs for the regression model.
Public propertyIntercept
Gets or sets the intercept value for the regression.
Public propertyNumberOfInputs
Gets the number of inputs accepted by the model.
(Overrides TransformBaseTInput, TOutputNumberOfInputs.)
Public propertyNumberOfOutputs
Gets the number of outputs generated by the model.
(Inherited from TransformBaseTInput, TOutput.)
Public propertyNumberOfParameters
Gets the number of parameters in this model (equals the NumberOfInputs + 1).
Public propertyWeights
Gets or sets the linear weights of the regression model. The intercept term is not stored in this vector, but is instead available through the Intercept property.
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
Public methodCoefficientOfDetermination
Gets the coefficient of determination, as known as R² (r-squared).
Public methodCompute(Double) Obsolete.
Computes the Multiple Linear Regression for an input vector.
Public methodCompute(Double) Obsolete.
Computes the Multiple Linear Regression for input vectors.
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.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRegress(Double, Double) Obsolete.
Performs the regression using the input vectors and output data, returning the sum of squared errors of the fit.
Public methodRegress(Double, Double, Boolean) Obsolete.
Performs the regression using the input vectors and output data, returning the sum of squared errors of the fit.
Public methodRegress(Double, Double, Double, Boolean) Obsolete.
Performs the regression using the input vectors and output data, returning the sum of squared errors of the fit.
Public methodToString
Returns a System.String representing the regression.
(Overrides ObjectToString.)
Public methodToString(String, IFormatProvider)
Returns a String that represents this instance.
Public methodTransform(TInput)
Applies the transformation to a set of input vectors, producing an associated set of output vectors.
(Inherited from TransformBaseTInput, TOutput.)
Public methodTransform(Double)
Applies the transformation to an input, producing an associated output.
(Overrides TransformBaseTInput, TOutputTransform(TInput).)
Public methodTransform(TInput, TOutput)
Applies the transformation to an input, producing an associated output.
(Inherited from TransformBaseTInput, TOutput.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(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.)
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 Matrix.)
Top
Remarks

In multiple linear regression, the model specification is that the dependent variable, denoted y_i, is a linear combination of the parameters (but need not be linear in the independent x_i variables). As the linear regression has a closed form solution, the regression coefficients can be computed by calling the Regress(Double, Double) method only once.

Examples

The following example shows how to fit a multiple linear regression model to model a plane as an equation in the form ax + by + c = z.

// We will try to model a plane as an equation in the form
// "ax + by + c = z". We have two input variables (x and y)
// and we will be trying to find two parameters a and b and 
// an intercept term c.

// We will use Ordinary Least Squares to create a
// linear regression model with an intercept term
var ols = new OrdinaryLeastSquares()
{
    UseIntercept = true
};

// Now suppose you have some points
double[][] inputs = 
{
    new double[] { 1, 1 },
    new double[] { 0, 1 },
    new double[] { 1, 0 },
    new double[] { 0, 0 },
};

// located in the same Z (z = 1)
double[] outputs = { 1, 1, 1, 1 };

// Use Ordinary Least Squares to estimate a regression model
MultipleLinearRegression regression = ols.Learn(inputs, outputs);

// As result, we will be given the following:
double a = regression.Weights[0]; // a = 0
double b = regression.Weights[1]; // b = 0
double c = regression.Intercept; // c = 1

// This is the plane described by the equation
// ax + by + c = z => 0x + 0y + 1 = z => 1 = z.

// We can compute the predicted points using
double[] predicted = regression.Transform(inputs);

// And the squared error loss using 
double error = new SquareLoss(outputs).Loss(predicted);
See Also