Skip to main content

predict

Function predict 

Source
pub fn predict(x_new: &Matrix, beta0: f64, beta: &[f64]) -> Vec<f64>
Expand description

Computes predictions using unstandardized coefficients.

§Arguments

  • x_new - New data matrix (n_new × p, with intercept column if applicable)
  • beta0 - Intercept on original scale
  • beta - Slope coefficients on original scale (does NOT include intercept column coefficient)

§Returns

Predictions for each row in x_new.

§Note

If x_new has an intercept column (first column of all ones), beta should have p - 1 elements corresponding to the non-intercept columns. If x_new has no intercept column, beta should have p elements.

§Example

// X matrix with intercept: [[1, 2], [1, 3], [1, 4]]
let x_new = Matrix::new(3, 2, vec![1.0, 2.0, 1.0, 3.0, 1.0, 4.0]);
let beta0 = 1.0;
let beta = vec![2.0];  // One slope coefficient

// predictions[i] = 1.0 + 2.0 * x[i,1]
let preds = predict(&x_new, beta0, &beta);
assert_eq!(preds, vec![5.0, 7.0, 9.0]);