Documentation of 'net.sourceforge.openforecast.models.MultipleLinearRegressionModel' Java class
MultipleLinearRegressionModel
net.sourceforge.openforecast.models

Class MultipleLinearRegressionModel

  • All Implemented Interfaces:
    ForecastingModel


    public class MultipleLinearRegressionModel
    extends AbstractForecastingModel
    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.
    Since:
    0.2
    • Constructor Summary

      Constructors 
      Constructor and Description
      MultipleLinearRegressionModel()
      A default constructor that constructs a new multiple variable Linear regression model.
      MultipleLinearRegressionModel(java.lang.String[] independentVariable)
      Constructs a new multiple variable linear regression model, using the given array of names as the independent variables to use.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      double forecast(DataPoint dataPoint)
      Using the current model parameters (initialized in init), apply the forecast model to the given data point.
      java.util.Hashtable<java.lang.String,java.lang.Double> getCoefficients()
      Returns a Hashtable containing the coefficients that will be used by the current model.
      java.lang.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, java.util.Hashtable<java.lang.String,java.lang.Double> coefficients)
      Initializes the coefficients to use for this regression model with the given values.
      java.lang.String toString()
      Returns a detailed description of this forcasting model, including the intercept and slope.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MultipleLinearRegressionModel

        public MultipleLinearRegressionModel()
        A default constructor that constructs a new multiple variable Linear regression model. When this constructor is used, it is assumed that all independent variables in the DataSet or list of coefficients passed to init are to be used in the model. To narrow down and explicitly define what independent variables to use in the model, use the alternate form of the constructor.

        For a valid model to be constructed, you should call either implementation of init.

        See Also:
        init(DataSet), init(double,Hashtable)
      • MultipleLinearRegressionModel

        public MultipleLinearRegressionModel(java.lang.String[] independentVariable)
        Constructs a new multiple variable linear regression model, using the given array of names as the independent variables to use. For a valid model to be constructed, you should call init and pass in a data set containing a series of data points involving the given independent variables.
        Parameters:
        independentVariable - an array of names of the independent variables to use in this model.
        See Also:
        init(DataSet), init(double,Hashtable)
    • Method Detail

      • init

        public void init(DataSet dataSet)
        Initializes the coefficients to use for this regression model. The coefficients are derived so as to give the best fit hyperplane for the given data set.

        Additionally, the accuracy indicators are calculated based on this data set.

        Parameters:
        dataSet - the set of observations to use to derive the regression coefficients for this model.
      • init

        public void init(double intercept,
                         java.util.Hashtable<java.lang.String,java.lang.Double> coefficients)
        Initializes the coefficients to use for this regression model with the given values. The coefficients Hashtable must contain a single entry for each independent variable. That entry should be accessible via the exact same name (case sensitive) as the independent variable, and should contain the intended coefficient value (as a subclass of Number).

        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.

        Parameters:
        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.
        Throws:
        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.
        java.lang.ClassCastException - if the "value" associated with one of the coefficients cannot be cast to a Number.
      • getIntercept

        public double getIntercept()
        Returns the intercept that will be used by the current model. This could be a user-defined value or internally calculated depending on which of the init methods was used to initialize the model.
        Returns:
        the intercept that will be used by this model.
        Throws:
        ModelNotInitializedException - if this method is called before the model has been initialized with a call to init.
      • getCoefficients

        public java.util.Hashtable<java.lang.String,java.lang.Double> getCoefficients()
        Returns a Hashtable containing the coefficients that will be used by the current model. These could be user-defined coefficients or internally calculated coefficients depending on which of the init methods were used to initialize the model.

        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.

        Returns:
        a Hashtable containing the coefficients that will be used by this model.
        Throws:
        ModelNotInitializedException - if this method is called before the model has been initialized with a call to init.
      • getNumberOfPredictors

        public int getNumberOfPredictors()
        Returns the number of predictors used by the underlying model.
        Returns:
        the number of predictors used by the underlying model.
      • forecast

        public double forecast(DataPoint dataPoint)
        Using the current model parameters (initialized in init), apply the forecast model to the given data point. The data point must have valid values for the independent variables. Upon return, the value of the dependent variable will be updated with the forecast value computed for that data point.
        Parameters:
        dataPoint - the data point for which a forecast value (for the dependent variable) is required.
        Returns:
        the forecast value of the dependent variable for the given data point.
        Throws:
        ModelNotInitializedException - if forecast is called before the model has been initialized with a call to init.
      • getForecastType

        public java.lang.String getForecastType()
        Returns a short name for this type of forecasting model. A more detailed explanation is provided by the toString method.
        Returns:
        a short string describing this type of forecasting model.
      • toString

        public java.lang.String toString()
        Returns a detailed description of this forcasting model, including the intercept and slope. A shortened version of this is provided by the getForecastType method.
        Specified by:
        toString in interface ForecastingModel
        Overrides:
        toString in class java.lang.Object
        Returns:
        a description of this forecasting model.

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.