uf3.regression.least_squares.BasicLinearModel

class BasicLinearModel(regularizer: Optional[numpy.ndarray] = None)[source]

Bases: object

Base class for linear regression.

Parameters

regularizer (np.ndarray) – regularization matrix.

Methods

fit

Direct solution to linear least squares with LU decomposition.

predict

Predict using fit coefficients.

score

Evaluate score (negative error metric).

fit(x: numpy.ndarray, y: numpy.ndarray, ridge_penalty: float = 1e-08)[source]

Direct solution to linear least squares with LU decomposition.

Parameters
  • x (np.ndarray) – input matrix of shape (n_samples, n_features).

  • y (np.ndarray) – output vector of length n_samples.

  • ridge_penalty (float) – magnitude of ridge penalty. Ignored if self.regularizer is set at initialization.

predict(x: numpy.ndarray)[source]

Predict using fit coefficients.

Parameters

x (np.ndarray) – input matrix of shape (n_samples, n_features).

Returns

vector of predictions.

Return type

predictions (np.ndarray)

score(x, y, weights=None, normalize=True)[source]

Evaluate score (negative error metric).

Parameters
  • x (np.ndarray) – input matrix of shape (n_samples, n_features).

  • y (np.ndarray) – output vector of length n_samples.

  • weights (np.ndarray) – sample weights (optional).

  • normalize (bool) – whether to normalize by the std of y.

Returns

negative weighted root-mean-square-error.

Return type

score (float)