NormodOLS#
- class sknormod.NormodOLS(*, fit_intercept=True, copy_X=True, n_jobs=None, positive=False)#
Normod in OLS. Fits a homoskedastic Gaussian using ordinary least squares. It is just scikit-learn LinearRegression, so the parameters are the same as to LinearRegression, but the fitted model is DistributionalRegressor, i.e., it has methods to get centiles or z-scores etc.
- Parameters:
- fit_interceptbool, default=True
Whether to calculate the intercept for this model. If set to False, no intercept will be used in calculations.
- copy_Xbool, default=True
Whether to copy the input data; if False, it may be overwritten.
- n_jobsint or None, default=None
The number of jobs to use for the computation. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.
- positivebool, default=False
When set to True, forces the coefficients to be positive.
Examples
>>> from sknormod.base import NormodOLS >>> import numpy as np >>> X = np.arange(100).reshape(100, 1) >>> y = np.zeros((100, )) >>> normod = NormodOLS() >>> normod.fit(X, y) NormodOLS()
Methods
fit
(X, y)Fit linear model.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
predict_distr_p
(X, p)Predict the percentiles of the distribution.
Predict distribution parameters for given input samples.
score
(X, y)Compute the logarithmic score of the predicted distribution parameters against the true values.
set_params
(**params)Set the parameters of this estimator.
transform_to_p
(X, y)Transform the target values to percentiles.
transform_to_z
(X, y)Transform the target values to z-scores.
- fit(X, y)#
Fit linear model.
- Parameters:
- Xarray-like or sparse matrix of shape (n_samples, n_features)
Training data.
- yarray-like of shape (n_samples,)
Target values.
- Returns:
- selfobject
Fitted estimator.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequest
encapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- predict_distr_p(X, p)#
Predict the percentiles of the distribution.
- Parameters:
- Xarray-like or sparse matrix of shape (n_samples, n_features)
The input samples.
- parray-like of shape (n_percentiles,)
The percentiles to predict.
- Returns:
- percentileslist of floats
The predicted percentiles.
- predict_distr_params(X)#
Predict distribution parameters for given input samples.
- Parameters:
- Xarray-like or sparse matrix of shape (n_samples, n_features)
Input samples.
- Returns:
- paramsarray-like of shape (n_samples, 2)
Predicted distribution parameters where each row represents [mu, sigma].
- score(X, y)#
Compute the logarithmic score of the predicted distribution parameters against the true values.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- transform_to_p(X, y)#
Transform the target values to percentiles.
- transform_to_z(X, y)#
Transform the target values to z-scores.