predict

Predicts the y value for a single x value using the fitted model.

Example:

val result = simpleLinearRegression(
x = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0),
y = doubleArrayOf(3.0, 5.0, 7.0, 9.0, 11.0)
)
result.predict(6.0) // 13.0

Return

the predicted y value (intercept + slope * x).

Parameters

x

the input value.


Predicts y values for an array of x values using the fitted model.

Example:

val result = simpleLinearRegression(
x = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0),
y = doubleArrayOf(3.0, 5.0, 7.0, 9.0, 11.0)
)
result.predict(doubleArrayOf(6.0, 7.0)) // [13.0, 15.0]

Return

an array of predicted y values, one per input.

Parameters

x

the array of input values.