Package org.pepstock.charba.client.ml
Class LinearRegression
- java.lang.Object
- 
- org.pepstock.charba.client.ml.LinearRegression
 
- 
- All Implemented Interfaces:
- IsRegression
 
 public final class LinearRegression extends Object Simple Linear Regression is a type of Regression algorithms that models the relationship between a dependent variable and a single independent variable.
 The relationship shown by a Simple Linear Regression model is linear or a sloped straight line, hence it is called Simple Linear Regression.
 The key point in Simple Linear Regression is that the dependent variable must be a continuous/real value.
 However, the independent variable can be measured on continuous or categorical values.
 The Simple Linear Regression model can be represented using the below equation:
 
 y = a0 + a1x
 
 where
 - a0 is the intercept of the Regression line (can be obtained putting x=0)
- a1 is the slope of the regression line, which tells whether the line is increasing or decreasing
 - Author:
- Andrea "Stock" Stocchero
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intDEFAULT_FORMULA_PRECISIONDefault precision to get the formula, 2.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description doublecomputeX(double y)Returns a calculated X value by the Y value.doublecomputeX(DataPoint dataPoint)Returns a calculated X value by the Y value.doublecomputeX(FloatingData y)Returns a calculated X value by the Y value.DatecomputeX(TimeSeriesItem item)Returns a calculated X value by the Y value.DatecomputeXToDate(double y)Returns a calculated X value by the Y value.DatecomputeXToDate(DataPoint dataPoint)Returns a calculated X value by the Y value.DatecomputeXToDate(FloatingData y)Returns a calculated X value by the Y value.List<Double>getCoefficients()Returns all calculated coefficients as a list.RegressionDescriptorgetDescriptor()Returns the regression descriptor.doublegetIntercept()Returns the intercept coefficient.doublegetSlope()Returns the slope coefficient.RegressionTypegetType()Returns the regression type.booleanisConsistent()Returnstrueif the regression is consistent and usable.doublepredict(double x)Returns the Y value, calculated by the regression formula at specific X value.List<Double>predict(double... xValues)Returns a list of Y values, calculated by the regression formula for specific X values.doublepredict(Date x)Returns the Y value, calculated by the regression formula at specific X value.List<Double>predict(List<Double> xValues)Returns a list of Y values, calculated by the regression formula for specific X values.doublepredict(DataPoint dataPoint)Returns the Y value, calculated by the regression formula at specific X value.doublepredict(TimeSeriesItem item)Returns the Y value, calculated by the regression formula at specific X value.List<Double>predictByDataPoints(List<DataPoint> dataPoints)Returns a list of Y values, calculated by the regression formula for specific X values.List<Double>predictByDataPoints(DataPoint... dataPoints)Returns a list of Y values, calculated by the regression formula for specific X values.List<Double>predictByDates(Date... xValues)Returns a list of Y values, calculated by the regression formula for specific X values.List<Double>predictByDates(List<Date> xValues)Returns a list of Y values, calculated by the regression formula for specific X values.List<Double>predictByTimeSeriesItems(List<TimeSeriesItem> items)Returns a list of Y values, calculated by the regression formula for specific X values.List<Double>predictByTimeSeriesItems(TimeSeriesItem... items)Returns a list of Y values, calculated by the regression formula for specific X values.RegressionScorescore(List<Double> y)Evaluates the regression formula if the model fits enough.
 X values are creating starting from 0 with increment of 1.RegressionScorescore(List<Double> y, double starting)Evaluates the regression formula if the model fits enough.
 X values are creating starting from passed argument with increment of 1.RegressionScorescore(List<Double> y, double starting, double increment)Evaluates the regression formula if the model fits enough.
 X values are creating starting from passed argument with increment of passed argument.RegressionScorescore(List<Double> x, List<Double> y)Evaluates the regression formula if the model fits enough.RegressionScorescoreByDataPoints(List<DataPoint> dataPoints)Evaluates the regression formula if the model fits enough.RegressionScorescoreByDate(List<Date> x, List<Double> y)Evaluates the regression formula if the model fits enough.RegressionScorescoreByTimeSeriesItems(List<TimeSeriesItem> items)Evaluates the regression formula if the model fits enough.StringtoFormula()Returns the formula of the regression.StringtoFormula(int precision)Returns the formula of the regression, using the requested precision.StringtoLaTeX()Returns the formula of the regression.StringtoLaTeX(int precision)Returns the formula of the regression, using the requested precision.
 
- 
- 
- 
Field Detail- 
DEFAULT_FORMULA_PRECISIONpublic static final int DEFAULT_FORMULA_PRECISION Default precision to get the formula, 2.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getSlopepublic final double getSlope() Returns the slope coefficient.- Returns:
- the slope coefficient
 
 - 
getInterceptpublic final double getIntercept() Returns the intercept coefficient.- Returns:
- the intercept coefficient
 
 - 
getCoefficientspublic final List<Double> getCoefficients() Returns all calculated coefficients as a list.- Returns:
- all calculated coefficients as a list
 
 - 
computeXpublic final double computeX(double y) Returns a calculated X value by the Y value.- Parameters:
- y- Y value to use to calculate the X value
- Returns:
- a calculated X value by the Y value
 
 - 
computeXpublic final double computeX(FloatingData y) Returns a calculated X value by the Y value.- Parameters:
- y- Y value to use to calculate the X value
- Returns:
- a calculated X value by the Y value
 
 - 
computeXpublic final double computeX(DataPoint dataPoint) Returns a calculated X value by the Y value.- Parameters:
- dataPoint- Y value to use to calculate the X value
- Returns:
- a calculated X value by the Y value
 
 - 
computeXpublic final Date computeX(TimeSeriesItem item) Returns a calculated X value by the Y value.- Parameters:
- item- Y value to use to calculate the X value
- Returns:
- a calculated X value by the Y value
 
 - 
computeXToDatepublic final Date computeXToDate(double y) Returns a calculated X value by the Y value.- Parameters:
- y- Y value to use to calculate the X value
- Returns:
- a calculated X value by the Y value
 
 - 
computeXToDatepublic final Date computeXToDate(FloatingData y) Returns a calculated X value by the Y value.- Parameters:
- y- Y value to use to calculate the X value
- Returns:
- a calculated X value by the Y value
 
 - 
computeXToDatepublic final Date computeXToDate(DataPoint dataPoint) Returns a calculated X value by the Y value.- Parameters:
- dataPoint- Y value to use to calculate the X value
- Returns:
- a calculated X value by the Y value
 
 - 
getTypepublic final RegressionType getType() Returns the regression type.- Specified by:
- getTypein interface- IsRegression
- Returns:
- the regression type
 
 - 
getDescriptorpublic final RegressionDescriptor getDescriptor() Returns the regression descriptor.- Specified by:
- getDescriptorin interface- IsRegression
- Returns:
- the regression descriptor
 
 - 
isConsistentpublic final boolean isConsistent() Description copied from interface:IsRegressionReturnstrueif the regression is consistent and usable.- Specified by:
- isConsistentin interface- IsRegression
- Returns:
- trueif the regression is consistent and usable
 
 - 
predictpublic final double predict(double x) Description copied from interface:IsRegressionReturns the Y value, calculated by the regression formula at specific X value.- Specified by:
- predictin interface- IsRegression
- Parameters:
- x- value to use to get the predicted value
- Returns:
- the Y value, calculated by the regression formula at specific X value
 
 - 
predictpublic final double predict(Date x) Description copied from interface:IsRegressionReturns the Y value, calculated by the regression formula at specific X value.- Specified by:
- predictin interface- IsRegression
- Parameters:
- x- value to use to get the predicted value
- Returns:
- the Y value, calculated by the regression formula at specific X value
 
 - 
predictpublic final double predict(DataPoint dataPoint) Description copied from interface:IsRegressionReturns the Y value, calculated by the regression formula at specific X value.- Specified by:
- predictin interface- IsRegression
- Parameters:
- dataPoint- value to use to get the predicted value
- Returns:
- the Y value, calculated by the regression formula at specific X value
 
 - 
predictpublic final double predict(TimeSeriesItem item) Description copied from interface:IsRegressionReturns the Y value, calculated by the regression formula at specific X value.- Specified by:
- predictin interface- IsRegression
- Parameters:
- item- value to use to get the predicted value
- Returns:
- the Y value, calculated by the regression formula at specific X value
 
 - 
predictpublic final List<Double> predict(double... xValues) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictin interface- IsRegression
- Parameters:
- xValues- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
predictpublic final List<Double> predict(List<Double> xValues) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictin interface- IsRegression
- Parameters:
- xValues- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
predictByDatespublic final List<Double> predictByDates(Date... xValues) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictByDatesin interface- IsRegression
- Parameters:
- xValues- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
predictByDatespublic final List<Double> predictByDates(List<Date> xValues) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictByDatesin interface- IsRegression
- Parameters:
- xValues- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
predictByDataPointspublic final List<Double> predictByDataPoints(DataPoint... dataPoints) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictByDataPointsin interface- IsRegression
- Parameters:
- dataPoints- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
predictByDataPointspublic final List<Double> predictByDataPoints(List<DataPoint> dataPoints) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictByDataPointsin interface- IsRegression
- Parameters:
- dataPoints- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
predictByTimeSeriesItemspublic final List<Double> predictByTimeSeriesItems(TimeSeriesItem... items) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictByTimeSeriesItemsin interface- IsRegression
- Parameters:
- items- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
predictByTimeSeriesItemspublic final List<Double> predictByTimeSeriesItems(List<TimeSeriesItem> items) Description copied from interface:IsRegressionReturns a list of Y values, calculated by the regression formula for specific X values.- Specified by:
- predictByTimeSeriesItemsin interface- IsRegression
- Parameters:
- items- values to use to get the predicted values
- Returns:
- a list of Y values, calculated by the regression formula for specific X values
 
 - 
scorepublic final RegressionScore score(List<Double> y) Description copied from interface:IsRegressionEvaluates the regression formula if the model fits enough.
 X values are creating starting from 0 with increment of 1.- Specified by:
- scorein interface- IsRegression
- Parameters:
- y- Y values to use for evaluation
- Returns:
- the score of the regression
 
 - 
scorepublic final RegressionScore score(List<Double> y, double starting) Description copied from interface:IsRegressionEvaluates the regression formula if the model fits enough.
 X values are creating starting from passed argument with increment of 1.- Specified by:
- scorein interface- IsRegression
- Parameters:
- y- Y values to use for evaluation
- starting- starting value to create X values
- Returns:
- the score of the regression
 
 - 
scorepublic final RegressionScore score(List<Double> y, double starting, double increment) Description copied from interface:IsRegressionEvaluates the regression formula if the model fits enough.
 X values are creating starting from passed argument with increment of passed argument.- Specified by:
- scorein interface- IsRegression
- Parameters:
- y- Y values to use for evaluation
- starting- starting value to create X values
- increment- increment to apply to the starting value
- Returns:
- the score of the regression
 
 - 
scorepublic final RegressionScore score(List<Double> x, List<Double> y) Description copied from interface:IsRegressionEvaluates the regression formula if the model fits enough.- Specified by:
- scorein interface- IsRegression
- Parameters:
- x- X values to use for evaluation
- y- Y values to use for evaluation
- Returns:
- the score of the regression
 
 - 
scoreByDatepublic final RegressionScore scoreByDate(List<Date> x, List<Double> y) Description copied from interface:IsRegressionEvaluates the regression formula if the model fits enough.- Specified by:
- scoreByDatein interface- IsRegression
- Parameters:
- x- X values to use for evaluation
- y- Y values to use for evaluation
- Returns:
- the score of the regression
 
 - 
scoreByDataPointspublic final RegressionScore scoreByDataPoints(List<DataPoint> dataPoints) Description copied from interface:IsRegressionEvaluates the regression formula if the model fits enough.- Specified by:
- scoreByDataPointsin interface- IsRegression
- Parameters:
- dataPoints- X and Y values to use for evaluation
- Returns:
- the score of the regression
 
 - 
scoreByTimeSeriesItemspublic final RegressionScore scoreByTimeSeriesItems(List<TimeSeriesItem> items) Description copied from interface:IsRegressionEvaluates the regression formula if the model fits enough.- Specified by:
- scoreByTimeSeriesItemsin interface- IsRegression
- Parameters:
- items- X and Y values to use for evaluation
- Returns:
- the score of the regression
 
 - 
toFormulapublic final String toFormula() Description copied from interface:IsRegressionReturns the formula of the regression.- Specified by:
- toFormulain interface- IsRegression
- Returns:
- the formula of the regression
 
 - 
toFormulapublic final String toFormula(int precision) Description copied from interface:IsRegressionReturns the formula of the regression, using the requested precision.- Specified by:
- toFormulain interface- IsRegression
- Parameters:
- precision- precision to apply to the numbers of the formula
- Returns:
- the formula of the regression
 
 - 
toLaTeXpublic final String toLaTeX() Description copied from interface:IsRegressionReturns the formula of the regression.- Specified by:
- toLaTeXin interface- IsRegression
- Returns:
- the formula of the regression
 
 - 
toLaTeXpublic final String toLaTeX(int precision) Description copied from interface:IsRegressionReturns the formula of the regression, using the requested precision.- Specified by:
- toLaTeXin interface- IsRegression
- Parameters:
- precision- precision to apply to the numbers of the formula
- Returns:
- the formula of the regression
 
 
- 
 
-