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

    Constructors
    Constructor
    Description
    LinearModel(double slope, double intercept, double rSquared)
    Creates an instance of a LinearModel record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    double
    Returns the value of the intercept record component.
    double
    predict(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.
    double
    Returns the value of the rSquared record component.
    double
    Returns the value of the slope record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LinearModel

      public LinearModel(double slope, double intercept, double rSquared)
      Creates an instance of a LinearModel record class.
      Parameters:
      slope - the value for the slope record component
      intercept - the value for the intercept record component
      rSquared - the value for the rSquared record component
  • 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

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • slope

      public double slope()
      Returns the value of the slope record component.
      Returns:
      the value of the slope record component
    • intercept

      public double intercept()
      Returns the value of the intercept record component.
      Returns:
      the value of the intercept record component
    • rSquared

      public double rSquared()
      Returns the value of the rSquared record component.
      Returns:
      the value of the rSquared record component