Statistics¶
This section documents the statistics components of the linear_model module.
statistics
¶
Defines sklearn.linear_model statistics interoperability.
This module provides functions to create Nextmv statistics objects from sklearn linear models.
FUNCTION | DESCRIPTION |
---|---|
LinearRegressionStatistics |
Creates a Nextmv statistics object from a sklearn.linear_model.LinearRegression model. |
LinearRegressionStatistics
¶
LinearRegressionStatistics(
model: LinearRegression,
X: Iterable,
y: Iterable,
sample_weight: float = None,
run_duration_start: Optional[float] = None,
) -> Statistics
Creates a Nextmv statistics object from a sklearn.linear_model.LinearRegression model.
You can import the LinearRegressionStatistics
function directly from linear_model
:
The statistics returned are quite basic, and should be extended according to the custom
metrics that the user wants to track. The optional run_duration_start
parameter
can be used to set the start time of the whole run.
PARAMETER | DESCRIPTION |
---|---|
|
The sklearn LinearRegression model.
TYPE:
|
|
The input samples.
TYPE:
|
|
The target values.
TYPE:
|
|
The sample weights, by default None.
TYPE:
|
|
The start time of the run, by default None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Statistics
|
The Nextmv statistics object with basic model metrics. |
Examples:
>>> from sklearn.linear_model import LinearRegression
>>> from nextmv_sklearn.linear_model import LinearRegressionStatistics
>>> import numpy as np
>>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
>>> y = np.dot(X, np.array([1, 2])) + 3
>>> model = LinearRegression()
>>> model.fit(X, y)
>>> stats = LinearRegressionStatistics(model, X, y)
>>> print(stats.result.custom['score']) # R^2 score
1.0