Record Class Regression.LinearModel
java.lang.Object
java.lang.Record
cloud.opencode.base.math.stats.Regression.LinearModel
- Record Components:
slope- the slope of the regression line / 回归线斜率intercept- the y-intercept of the regression line / 回归线截距rSquared- the coefficient of determination (R^2) / 决定系数(R^2)
- Enclosing class:
Regression
public static record Regression.LinearModel(double slope, double intercept, double rSquared)
extends Record
Result of a linear regression: y = slope * x + intercept.
线性回归结果:y = slope * x + intercept
- Since:
- JDK 25, opencode-base-math V1.0.3
- Author:
- Leon Soo
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLinearModel(double slope, double intercept, double rSquared) Creates an instance of aLinearModelrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doubleReturns the value of theinterceptrecord component.doublepredict(double x) Predicts the y value for a given x.double[]residuals(double[] x, double[] y) Computes residuals (y_actual - y_predicted) for the given data.doublerSquared()Returns the value of therSquaredrecord component.doubleslope()Returns the value of thesloperecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
LinearModel
-
-
Method Details
-
predict
public double predict(double x) Predicts the y value for a given x. 预测给定 x 值对应的 y 值- Parameters:
x- the independent variable value / 自变量值- Returns:
- the predicted y value / 预测的 y 值
-
residuals
public double[] residuals(double[] x, double[] y) Computes residuals (y_actual - y_predicted) for the given data. 计算给定数据的残差(实际值 - 预测值)- Parameters:
x- the independent variable values / 自变量值y- the actual dependent variable values / 实际因变量值- Returns:
- array of residuals / 残差数组
- Throws:
IllegalArgumentException- if arrays are null, empty, or different lengths
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
slope
-
intercept
-
rSquared
-