|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.openforecast.models.AbstractForecastingModel net.sourceforge.openforecast.models.MultipleLinearRegressionModel
public class MultipleLinearRegressionModel
Implements a multiple variable linear regression model using the variables named in the constructor as the independent variables, or the variables passed into one of the init methods. The cofficients of the regression, as well as the accuracy indicators are determined from the data set passed to init.
Once initialized, this model can be applied to another data set using the forecast method to forecast values of the dependent variable based on values of the dependent variable (the one named in the constructor).
A multiple variable linear regression model essentially attempts to put a hyperplane through the data points. Mathematically, assuming the independent variables are xi and the dependent variable is y, then this hyperplane can be represented as:
y = a0 + a1*x1 + a2*x2 + a3*x3 + ...where the ai are the coefficients of the regression. The coefficient a0 is also referred to as the intercept. If all xi were zero (theoretically at least), it is the forecast value of the dependentVariable, y.
Field Summary |
---|
Fields inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel |
---|
accuracyIndicators, initialized |
Constructor Summary | |
---|---|
MultipleLinearRegressionModel()
A default constructor that constructs a new multiple variable Linear regression model. |
|
MultipleLinearRegressionModel(String[] independentVariable)
Constructs a new multiple variable linear regression model, using the given array of names as the independent variables to use. |
Method Summary | |
---|---|
double |
forecast(DataPoint dataPoint)
Using the current model parameters (initialized in init), apply the forecast model to the given data point. |
Hashtable<String,Double> |
getCoefficients()
Returns a Hashtable containing the coefficients that will be used by the current model. |
String |
getForecastType()
Returns a short name for this type of forecasting model. |
double |
getIntercept()
Returns the intercept that will be used by the current model. |
int |
getNumberOfPredictors()
Returns the number of predictors used by the underlying model. |
void |
init(DataSet dataSet)
Initializes the coefficients to use for this regression model. |
void |
init(double intercept,
Hashtable<String,Double> coefficients)
Initializes the coefficients to use for this regression model with the given values. |
String |
toString()
Returns a detailed description of this forcasting model, including the intercept and slope. |
Methods inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel |
---|
calculateAccuracyIndicators, forecast, getAIC, getBias, getMAD, getMAPE, getMSE, getSAE |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MultipleLinearRegressionModel()
For a valid model to be constructed, you should call either implementation of init.
init(DataSet)
,
init(double,Hashtable)
public MultipleLinearRegressionModel(String[] independentVariable)
independentVariable
- an array of names of the independent
variables to use in this model.init(DataSet)
,
init(double,Hashtable)
Method Detail |
---|
public void init(DataSet dataSet)
Additionally, the accuracy indicators are calculated based on this data set.
dataSet
- the set of observations to use to derive the regression
coefficients for this model.public void init(double intercept, Hashtable<String,Double> coefficients)
In addition to the coefficients, you must also specify the constant term - or the "intercept" - to use in the regression model.
Note that since this method does not require a data set, it is not possible to calculate the values of the accuracy indicators. Therefore these are all set to their worse-case values.
intercept
- the constant term - or the "intercept" - to use in
the regression model.coefficients
- the coefficients to be assigned for use in this
regression model.
ModelNotInitializedException
- if a coefficient does not exist
in the given Hashtable of coefficients for one or more of the
independent variables used when constructing this model.
ClassCastException
- if the "value" associated with one of the
coefficients cannot be cast to a Number.public double getIntercept()
ModelNotInitializedException
- if this method is called before
the model has been initialized with a call to init.public Hashtable<String,Double> getCoefficients()
Note that modifying the coefficients in the Hashtable returned from
this method will not modify the coefficients used by the model. If you
want to modify the coefficients used in the model, then use the
init(double,Hashtable)
method to re-initialize the model.
ModelNotInitializedException
- if this method is called before
the model has been initialized with a call to init.public int getNumberOfPredictors()
public double forecast(DataPoint dataPoint)
dataPoint
- the data point for which a forecast value (for the
dependent variable) is required.
ModelNotInitializedException
- if forecast is called before the
model has been initialized with a call to init.public String getForecastType()
public String toString()
toString
in interface ForecastingModel
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |