类 LinearRegression
- java.lang.Object
-
- edu.princeton.cs.algs4.LinearRegression
-
public class LinearRegression extends java.lang.ObjectTheLinearRegressionclass performs a simple linear regression on an set of n data points (yi, xi). That is, it fits a straight line y = α + β x, (where y is the response variable, x is the predictor variable, α is the y-intercept, and β is the slope) that minimizes the sum of squared residuals of the linear regression model. It also computes associated statistics, including the coefficient of determination R2 and the standard deviation of the estimates for the slope and y-intercept.
-
-
构造器概要
构造器 构造器 说明 LinearRegression(double[] x, double[] y)Performs a linear regression on the data points(y[i], x[i]).
-
方法概要
修饰符和类型 方法 说明 doubleintercept()Returns the y-intercept α of the best of the best-fit line y = α + β x.doubleinterceptStdErr()Returns the standard error of the estimate for the intercept.doublepredict(double x)Returns the expected responseygiven the value of the predictor variablex.doubleR2()Returns the coefficient of determination R2.doubleslope()Returns the slope β of the best of the best-fit line y = α + β x.doubleslopeStdErr()Returns the standard error of the estimate for the slope.java.lang.StringtoString()Returns a string representation of the simple linear regression model.
-
-
-
构造器详细资料
-
LinearRegression
public LinearRegression(double[] x, double[] y)Performs a linear regression on the data points(y[i], x[i]).- 参数:
x- the values of the predictor variabley- the corresponding values of the response variable- 抛出:
java.lang.IllegalArgumentException- if the lengths of the two arrays are not equal
-
-
方法详细资料
-
intercept
public double intercept()
Returns the y-intercept α of the best of the best-fit line y = α + β x.- 返回:
- the y-intercept α of the best-fit line y = α + β x
-
slope
public double slope()
Returns the slope β of the best of the best-fit line y = α + β x.- 返回:
- the slope β of the best-fit line y = α + β x
-
R2
public double R2()
Returns the coefficient of determination R2.- 返回:
- the coefficient of determination R2, which is a real number between 0 and 1
-
interceptStdErr
public double interceptStdErr()
Returns the standard error of the estimate for the intercept.- 返回:
- the standard error of the estimate for the intercept
-
slopeStdErr
public double slopeStdErr()
Returns the standard error of the estimate for the slope.- 返回:
- the standard error of the estimate for the slope
-
predict
public double predict(double x)
Returns the expected responseygiven the value of the predictor variablex.- 参数:
x- the value of the predictor variable- 返回:
- the expected response
ygiven the value of the predictor variablex
-
toString
public java.lang.String toString()
Returns a string representation of the simple linear regression model.- 覆盖:
toString在类中java.lang.Object- 返回:
- a string representation of the simple linear regression model, including the best-fit line and the coefficient of determination R2
-
-