cyclic_boosting.smoothing package#
Submodules#
cyclic_boosting.smoothing.base module#
Base classes for smoothers
- class cyclic_boosting.smoothing.base.AbstractBinSmoother[source]#
Bases:
BaseEstimator
,RegressorMixin
Abstract base class for smoothers acting on bins.
Please implement the methods
fit
andpredict
.- inc_fitting = False#
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') AbstractBinSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- supports_pandas = False#
cyclic_boosting.smoothing.extrapolate module#
Smoothers capable of extrapolating beyond the range seen in the training
The most common example is extrapolating a target profile or factor profile into the future, i.e. the smoother can be used to extend the profile beyond the time range seen in the training. In this case, the smoother operates on the feature time.
Note
Using these components requires regular retraining, because the extrapolation originates at the end of the training interval and will become more and more uncertain over time.
don’t use
cyclic_boosting.binning.FractionalBinNumberTransformer
on features these smoothers operate on, because they just assign the largest bin number to feature values beyond the upper bound seen in the training which prevents any extrapolation.
For the time feature, LinearBinner
is usually sufficient,
because the amount of samples per time interval usually doesn’t vary that
much over time.
Extrapolation is not needed for times within some period, e.g. for the weekday, the month day or the day number in the year. Please use normal smoothers for that.
- class cyclic_boosting.smoothing.extrapolate.LinearExtrapolator(epsilon=0.0001)[source]#
Bases:
AbstractBinSmoother
Smoother of one-dimensional bins that applies a linear regression to fit the bin values of y (as received from the profile function in the fit) and applies a linear interpolation in predict.
The
math_utils.linear_regression()
is used for the regression. The uncertainties \(\sigma_i\) of y are transformed to the weights \(w_i = \frac{1}{(\sigma_i)^2 + \epsilon}\) needed bylinear_regression()
in the fit method. An epsilon value is added to avoid zero division.- Parameters:
epsilon (float) – Epsilon value to avoid zero division when transforming the uncertainties to the weights.
Required columns in the
X_for_smoother
passed tofit()
:column 0: …
column 1: ignored
column 2: uncertainty of the average
y
in each bin
These are provided by the following profile functions:
BetaMeanSigmaProfile
Used column in the
predict()
:column 0: …
Estimated parameters
- Parameters:
alpha_ (
float
) – axis interceptionbeta_ (
float
) – slope
Small data example
>>> np.random.seed(4) >>> n = 5 >>> x = np.arange(n) >>> alpha = 3.0 >>> beta = 0.5 >>> y = alpha + beta * x >>> y array([ 3. , 3.5, 4. , 4.5, 5. ]) >>> y_err = np.array([np.mean(np.random.randn(n)) for i in range(n)]) >>> y_smeared = y + y_err >>> y_smeared array([ 2.96598022, 3.01021291, 4.02623841, 4.91211327, 5.04914922])
>>> X = np.c_[x, np.ones(n), y_err]
>>> from cyclic_boosting.smoothing.extrapolate import LinearExtrapolator >>> est = LinearExtrapolator() >>> est = est.fit(X, y_smeared)
>>> from decimal import Decimal >>> Decimal(est.alpha_).quantize(Decimal("1.000")) Decimal('2.971') >>> Decimal(est.beta_).quantize(Decimal("1.000")) Decimal('0.523')
>>> x1 = np.array([-7, -5, -3, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9., 20.]) >>> X1 = np.c_[x1] >>> est.predict(X1) array([ -0.69276543, 0.354095 , 1.40095542, 2.44781584, 2.97124605, 3.49467626, 4.01810647, 4.54153668, 5.06496689, 5.5883971 , 6.11182731, 6.63525752, 7.15868773, 7.68211794, 13.43985026])
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') LinearExtrapolator #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') LinearExtrapolator #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
cyclic_boosting.smoothing.meta_smoother module#
base module for abstract smoothers
- class cyclic_boosting.smoothing.meta_smoother.NormalizationRegressionTypeSmoother(smoother, reg_type)[source]#
Bases:
NormalizationSmoother
,RegressionTypeSmoother
Meta-smoother to constrain all values according to their
RegressionType
from thepredict
method of the subsmoother.- Parameters:
smoother (
AbstractBinSmoother
) – smoother used to fit and predict on the normalized data points.reg_type (
RegressionType
) – defines the regression type that is used to constrain the values.Types (Regression) –
---------------- –
discontinuous (*) – boundries in the fit or where no fit events have been seen.
interpolating (*) – boundries in the fit.
extrapolating (*) –
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') NormalizationRegressionTypeSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') NormalizationRegressionTypeSmoother #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') NormalizationRegressionTypeSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.meta_smoother.NormalizationSmoother(smoother)[source]#
Bases:
AbstractBinSmoother
Meta-smoother that normalizes the values for its subestimator.
- Parameters:
smoother (
AbstractBinSmoother
) – smoother used to fit and predict on the normalized data points.
- calc_norm(X_for_smoother, y)[source]#
Calculate the weighted mean of the target y that can then be used to give the subestimator a normalized distribution.
- Parameters:
X_for_smoother (
numpy.ndarray
) – Multidimensional array with at least three columns. For a k-dimensional feature the first k columns contain the x-values for the smoothing. Thek + 1
column are the weights of these x-values, while thek + 2
column contains the uncertainties.smoothed_y (
numpy.ndarray
) – Array that contains the original target values.
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') NormalizationSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') NormalizationSmoother #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') NormalizationSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.meta_smoother.RegressionTypeSmoother(smoother, reg_type)[source]#
Bases:
AbstractBinSmoother
,SetNBinsMixin
Meta-smoother to constrain all values according to their
RegressionType
from thepredict
method of the subsmoother.- Parameters:
smoother (
AbstractBinSmoother
) – smoother used to fit and predict on the normalized data points.reg_type (
RegressionType
) – defines the regression type that is used to constrain the values.Types (Regression) –
---------------- –
discontinuous (*) – boundries in the fit or where no fit events have been seen.
interpolating (*) – boundries in the fit.
extrapolating (*) –
- apply_cut(X_for_smoother, smoothed_y)[source]#
Constrain all values in smoothed_y according to their
RegressionType
.- Parameters:
X_for_smoother (
numpy.ndarray
) – Multidimensional array with at least three columns. For a k-dimensional feature the first k columns contain the x-values for the smoothing. Thek + 1
column are the weights of these x-values, while thek + 2
column contains the uncertainties.smoothed_y (
numpy.ndarray
) – Array that contains the result of the subsmoother.
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') RegressionTypeSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') RegressionTypeSmoother #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') RegressionTypeSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.meta_smoother.SectionSmoother(split_point, smoother_lower, smoother_upper, nan_representation=nan, epsilon=0.001)[source]#
Bases:
AbstractBinSmoother
Meta-smoother that splits the fitted data into two parts which are fitted by different subsmoothers.
- Parameters:
split_point (float) – value of x to split the data \(x_{below} <= C_{split} < x_{above}\)
smoother_lower (
AbstractBinSmoother
) – smoother used to fit and predict on the data points below and including the split_pointsmoother_upper (
AbstractBinSmoother
) – smoother used to fit and predict on the data points above the split_pointnan_representation (float) – optional argument to define
not a number values
(default =np.nan
).epsilon (float) – Floating point accuracy when comparing with the
split_point
. (E.g. \(x_{below} <= C_{split} + /epsilon\))
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') SectionSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') SectionSmoother #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SectionSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
cyclic_boosting.smoothing.multidim module#
Multidimensional smoothers
- class cyclic_boosting.smoothing.multidim.BinValuesSmoother[source]#
Bases:
AbstractBinSmoother
,PredictingBinValueMixin
Smoother of multidimensional bins that outputs the saved bin values of y (as received from the profile function in the fit) as the prediction.
This smoother only considers the first
n_dim
columns ofX_for_smoother
passed by the profile function. These columns are supposed to contain all the coordinates of then_dim
-dimensional bin centers.Estimated parameters
- Parameters:
smoothed_y_ (
numpy.ndarray
(float64, shape (n_bins,))) – the bin values fory
(as received from the profile function in the fit), in this case without any smoothing; a pseudobin for the missing values is not supportedn_bins_ – see
PredictingBinValueMixin
>>> from cyclic_boosting import smoothing >>> X = np.c_[[0., 0, 1, 1], ... [0, 1, 0, 1], ... [1, 1, 1, 1]] # ignored >>> y = np.array([90, 80, 50, 40])
>>> reg = smoothing.multidim.BinValuesSmoother() >>> assert reg.fit(X, y) is reg >>> assert np.allclose(reg.smoothed_y_, y) >>> X = np.c_[[1.1, 0.4, 0.0, 0.1, 2.], ... [1.2, 1.1, 0.4, 0.4, 0.]] >>> reg.predict(X) array([ 40., 80., 90., 90., nan])
- elems = ['smoothed_y_', 'bin_weights_']#
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') BinValuesSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BinValuesSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.multidim.GroupBySmoother(est, n_dim, index_weight_col=None)[source]#
Bases:
AbstractBinSmoother
Multidimensional smoother that groups on the first k-1 columns of a k dimensional feature and smoothes a clone of the specified 1-dimensional smoother on each group.
- Parameters:
est (
AbstractBinSmoother
) – One-dimensional smoother whose clones are fitted on the grouped columnsndim (int) – Number of dimensions of the feature.
index_weight_col (int) – Index of weight column. If specified, rows with zero weight are removed. If None, no rows are dropped.
- property n_group_columns#
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') GroupBySmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') GroupBySmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.multidim.GroupBySmootherCB(est, n_dim)[source]#
Bases:
GroupBySmoother
GroupBySmoother for cyclic boosting. Samples with zero weights are dropped to save memory.
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') GroupBySmootherCB #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') GroupBySmootherCB #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.multidim.Neutralize2DMetaSmoother(est)[source]#
Bases:
AbstractBinSmoother
,PredictingBinValueMixin
Meta-Smoother that takes another multi-dimensional smoother which inputs are smoothed by neutralize_one_dim_influence.
This means, the influence of one-dimensional features on two-dimensional features is removed by iteratively projecting the two-dimensional factor matrix onto one dimension and substract this weighted by the uncertainties from the matrix.
In a cyclic boosting model this prevents two-dimensional features to include the effect which should be learned by the one-dimension features.
cyclic_boosting.utils.neutralize_one_dim_influence()
.- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') Neutralize2DMetaSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') Neutralize2DMetaSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.multidim.PredictingBinValueMixin[source]#
Bases:
SetNBinsMixin
Mixin for smoothers of multidimensional bins with
predict()
returning the corresponding entry in the estimated parametersmoothed_y_
which must have been calculated infit()
.Please create the array
smoothed_y_
in yourfit()
method.Estimated parameters
- Parameters:
smoothed_y_ (
numpy.ndarray
(float64, shape (n_bins,))) – the bin values fory
(as received from the profile function in the fit) after some smoothing; a pseudobin for the missing values is not supported; the values are indexed in lexicographical ordering using then_bins_ (
numpy.ndarray
(int64, shape (n_dims + x,))) –number of bins in each dimension; it is permitted to append additional entries to this array. They are ignored in
predict()
anyway.Please use
set_n_bins()
to initialize this estimated parameter in your implementation offit()
.
For examples, see the subclass
BinValuesSmoother
.
- class cyclic_boosting.smoothing.multidim.RegularizeToOneSmoother(threshold=2.5)[source]#
Bases:
RegularizeToPriorExpectationSmoother
Smoother for multidimensional bins regularizing values with uncertainties to the prior expectation 1.
For details, see the superclass
RegularizeToPriorExpectationSmoother
and the underlying functioncyclic_boosting.utils.regularize_to_prior_expectation()
.- Parameters:
threshold (float) – threshold in terms of sigma. If the significance of a factor is below the threshold, the global measurement replaces the factor. Internally
cyclic_boosting.utils.regularize_to_prior_expectation()
is used.
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') RegularizeToOneSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') RegularizeToOneSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.multidim.RegularizeToPriorExpectationSmoother(prior_expectation, threshold=2.5)[source]#
Bases:
AbstractBinSmoother
,PredictingBinValueMixin
Smoother of multidimensional bins regularizing values with uncertainties to a prior expectation.
For details, see
cyclic_boosting.utils.regularize_to_prior_expectation()
.- Parameters:
prior_expectation (
numpy.ndarray
(float64, dim=1) or float) – The prior dominate the regularized value if the uncertainties are large.threshold (float) –
Threshold in terms of sigma. If the significance of a value:
\[\text{sig}(x_i) = \frac{x_i - \text{prior\_expectation}_i} {\text{uncertainty}_i}\]is below the threshold, the prior expectation replaces the value.
Required columns in the
X_for_smoother
passed tofit()
:columns 0 to``n_dim - 1``: coordinates of the bin centers (ignored here)
column
n_dim
: ignoredcolumn
n_dim + 1
, which must be the last: uncertainty of the averagey
in each bin
Doctests
>>> from cyclic_boosting import smoothing >>> y = np.array([0, 1, 2, 3]) >>> X = np.c_[ ... [0, 0, 1, 1], ... [0, 1, 0, 1], ... [1]*4, ... [0.1]*4] >>> est = smoothing.multidim.RegularizeToPriorExpectationSmoother(1.) >>> assert est.fit(X, y) is est >>> y_smoothed = est.predict(X[:, :2]) >>> y_smoothed array([ 0.03175416, 1. , 1.96824584, 2.98431348]) >>> np.allclose(1 - np.sqrt(((y[0] - 1) / 0.1)**2 - 2.5**2) * 0.1, ... y_smoothed[0]) True >>> np.allclose(1 + np.sqrt(((y[-1] - 1) / 0.1)**2 - 2.5**2) * 0.1, ... y_smoothed[-1]) True
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') RegularizeToPriorExpectationSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') RegularizeToPriorExpectationSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.multidim.WeightedMeanSmoother(prior_prediction=None)[source]#
Bases:
AbstractBinSmoother
,PredictingBinValueMixin
Smoother for multidimensional bins regularizing values with uncertainties to the weighted mean.
For details see
cyclic_boosting.utils.regularize_to_error_weighted_mean()
.- Parameters:
prior_prediction (float) – If the prior_prediction is specified, all values are regularized with it and not with the error weighted mean.
>>> from cyclic_boosting import smoothing >>> y_for_smoother = np.array([0.9, 0.9, 0.9, 1.8, 1.8, 0.4, 0.4]) >>> X_for_smoother = np.c_[ ... [1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0], ... [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0], ... [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ... [0.05, 0.05, 0.05, 0.05, 0.15, 0.15, 0.05]] >>> smoother = smoothing.multidim.WeightedMeanSmoother() >>> smoother.fit(X_for_smoother, y_for_smoother) >>> smoother.smoothed_y_ array([ 0.90096366, 0.90096366, 0.90096366, 1.79077293, 1.723854 , 0.45467402, 0.40662518])
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') WeightedMeanSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') WeightedMeanSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
cyclic_boosting.smoothing.onedim module#
One-dimensional smoothers
- class cyclic_boosting.smoothing.onedim.BinValuesSmoother[source]#
Bases:
AbstractBinSmoother
,PredictingBinValueMixin
Smoother that does not perform any smoothing (the identity smoother so to speak).
Smoother of one-dimensional bins that outputs the saved bin values of y (as received from the profile function in the fit) as the prediction. This smoother has no requirements on
X_for_smoother
passed by the profile function, because it just saves the target valuesy
and ignoresX_for_smoother
completely.Estimated parameters
- Parameters:
smoothed_y_ (
numpy.ndarray
(float64, shape (n_bins,))) – the bin values fory
(as received from the profile function in the fit) after some smoothing. a pseudobin for the missing values is not supported
>>> X = np.c_[[0., 1, 2, 3], ... [1, 1, 1, 1]] >>> y = np.array([90, 80, 50, 40])
>>> from cyclic_boosting.smoothing.onedim import BinValuesSmoother >>> reg = BinValuesSmoother() >>> assert reg.fit(X, y) is reg >>> assert np.allclose(reg.smoothed_y_, y) >>> X = np.c_[[3.1, 0.4, 1, 2.9, 3.4, 4.5]] >>> reg.predict(X) array([ 40., 90., 80., 40., 40., nan])
- elem = 'smoothed_y_'#
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') BinValuesSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') BinValuesSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.IsotonicRegressor(increasing='auto')[source]#
Bases:
AbstractBinSmoother
Wrapper which delegates to
sklearn.isotonic.IsotonicRegression
. Use if you expect a feature to be monotonic. An example is given in http://scikit-learn.org/stable/modules/isotonic.html .- Parameters:
increasing (boolean or string, optional, default: "auto") –
If boolean, whether or not to fit the isotonic regression with y increasing or decreasing.
The string value “auto” determines whether y should increase or decrease based on the Spearman correlation estimate’s sign.
Note
X requires the following columns.
- column0 :
…
- column1 :
ignored
- column2 :
weights
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') IsotonicRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') IsotonicRegressor #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.LSQUnivariateSpline(interior_knots, degree=3)[source]#
Bases:
AbstractBinSmoother
Wrapper which delegates to
scipy.interpolate.LSQUnivariateSpline
.- Parameters:
degree (int) – Degree of the smoothing spline, must be
1 <= k <= 5
. The number of data points must be greater than the spline degree.interior_knots (list) – Interior knots of the spline. Must be in ascending order.
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') LSQUnivariateSpline #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') LSQUnivariateSpline #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.OrthogonalPolynomialSmoother[source]#
Bases:
AbstractBinSmoother
A polynomial fit that uses orthogonal polynomials as basis functions.
Ansatz, see Blobel (http://www.desy.de/~blobel/eBuch.pdf)
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') OrthogonalPolynomialSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') OrthogonalPolynomialSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.PolynomialSmoother(k)[source]#
Bases:
AbstractBinSmoother
Least squares polynomial fit.
Fit a polynomial
p(x) = p[0] * x**deg + ... + p[deg]
of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error.This class delegates to
numpy.polyfit
.Required columns in the
X_for_smoother
passed tofit()
:column 0: …
column 1: ignored
column 2: uncertainty of the average
y
in each bin
These are provided by the following profile functions:
MeanProfile
BetaMeanSigmaProfile
- Parameters:
k (int) – Degree of the polynomial.
Estimated parameters
- Parameters:
coefficients_ (
numpy.ndarray
of length k) – Array of coefficients.
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') PolynomialSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') PolynomialSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.PredictingBinValueMixin[source]#
Bases:
object
Mixin for smoothers of one-dimensional bins with
predict()
returning the corresponding entry in the estimated parametersmoothed_y_
which must have been calculated infit()
.Please create the array
smoothed_y_
in yourfit()
method.Estimated parameters
- Parameters:
smoothed_y_ (
numpy.ndarray
(float64, shape (n_bins,))) – the bin values fory
(as received from the profile function in the fit) after some smoothing. a pseudobin for the missing values is not supported
For examples, see the subclasses
BinValuesSmoother
andBinKernelSmoother
.
- class cyclic_boosting.smoothing.onedim.RegularizeToOneSmoother(threshold=2.5)[source]#
Bases:
RegularizeToPriorExpectationSmoother
Smoother for one-dimensional bins regularizing values with uncertainties to the mean of the values.
- Parameters:
threshold (float) – threshold in terms of sigma. If the significance of a factor is below the threshold, the global measurement replaces the factor.
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') RegularizeToOneSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') RegularizeToOneSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.RegularizeToPriorExpectationSmoother(prior_expectation, threshold=2.5)[source]#
Bases:
AbstractBinSmoother
,PredictingBinValueMixin
Smoother of one-dimensional bins regularizing values with uncertainties to a prior expectation.
- Parameters:
prior_expectation (
numpy.ndarray
(float64, dim=1) or float) – The prior dominate the regularized value if the uncertainties are large.threshold (float) –
Threshold in terms of sigma. If the significance of a value:
\[\text{sig}(x_i) = \frac{x_i - \text{prior\_expectation}_i} {\text{uncertainty}_i}\]is below the threshold, the prior expectation replaces the value.
Required columns in the
X_for_smoother
passed tofit()
:column 0: …
column 1: ignored
column 2: uncertainty of the average
y
in each bin
Doctests
>>> y = np.array([0, 1, 2, 3]) >>> X = np.c_[ ... [0, 1, 2, 3], ... [1]*4, ... [0.1]*4] >>> from cyclic_boosting.smoothing.onedim import RegularizeToPriorExpectationSmoother >>> est = RegularizeToPriorExpectationSmoother(1.) >>> assert est.fit(X, y) is est >>> y_smoothed = est.predict(X[:, [0]]) >>> y_smoothed array([ 0.03175416, 1. , 1.96824584, 2.98431348]) >>> np.allclose(1 - np.sqrt(((y[0] - 1) / 0.1)**2 - 2.5**2) * 0.1, ... y_smoothed[0]) True >>> np.allclose(1 + np.sqrt(((y[-1] - 1) / 0.1)**2 - 2.5**2) * 0.1, ... y_smoothed[-1]) True
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') RegularizeToPriorExpectationSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') RegularizeToPriorExpectationSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.SeasonalLassoSmoother(min_days=300)[source]#
Bases:
AbstractBinSmoother
Seasonal Smoother of one-dimensional bins that applies a first order sine/cosine fit to smooth the bin values of y and returns the smoothed values as the prediction.
Lasso Regularization is used to reduce the influence of outliers.
If the number of days in the year where data is available remains below the configured threshold, the fallback value 0 is returned.
- Parameters:
min_days (int) – The smoother is only fitted if more than min_days bins of data are available. Otherwise, it is set to fallback_mode and no smoothing is done. (default=300)
Notes
Required columns in the
X_for_smoother
passed tofit()
:column 0: …
column 1: The number of samples in the bin
column 2: uncertainty of the average
y
in each bin (ignored)
- est#
The fitted sklearn.LassoLarsIC estimator
- Type:
sklearn.estimator
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') SeasonalLassoSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SeasonalLassoSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.SeasonalSmoother(offset_tozero=True, order=1, custom_fit_function=None, fallback_value=0.0)[source]#
Bases:
AbstractBinSmoother
Seasonal Smoother of one-dimensional bins that applies an sinus/cosinus fit to smooth the bin values of y (as received from the profile function in the fit) and returns the polynomial values as the prediction.
By default, SeasonalSmoother uses the the function
f(x) = c_const + c_sin * np.sin(x) + c_cos * np.cos(x)
for the fit. The constant offsetc_const
is ignored ifoffset_tozero
is set otTrue
(default). With higherorder
, terms with frequency2*x
and possibly3*x
are added.Instead of specifying an order, a custom fit-function can be supplied via the
custom_fit_function
argument.- Parameters:
offset_tozero (bool) – If
True
sets the constant offset to zero (default=True)order (int) – Order k of the series sin(k * x) + cos(k * x). Per default this is 1 and supported for order 2 and 3.
custom_fit_function (function) – User defined function to define a custom fit function for the seasonal smoother. In this case the order parameter is ignored.
fallback_value (float) – User defined parameter that is used when the fit does not converge
Notes
def my_custom_fit_function(x, *params): return ...
Required columns in the
X_for_smoother
passed tofit()
:column 0: …
column 1: ignored
column 2: uncertainty of the average
y
in each bin
These are provided by the following profile functions:
BetaMeanSigmaProfile
MeanProfile
- frequency_#
Frequency calculated from the maximum binnumber.
- Type:
float
- par_#
Parameters from the fit.
- Type:
numpy.ndarray
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') SeasonalSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SeasonalSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.UnivariateSplineSmoother(k=3, s=None)[source]#
Bases:
AbstractBinSmoother
Smoother of one-dimensional bins that applies a univariate spline fit to smooth the bin values of y (as received from the profile function in the fit) and returns the spline values as the prediction.
This class delegates to
scipy.interpolate.UnivariateSpline
.Required columns in the
X_for_smoother
passed tofit()
:column 0: …
column 1: weight sum in each bin
These are provided by the following profile functions:
MeanProfile
BetaMeanSigmaProfile
- Parameters:
k (int) – Degree of the smoothing spline, must be
<= 5
. The number of the data points must be larger than the spline degree.s (
float
or None) –Positive smoothing factor used to choose the number of knots. The number of knots will be increased until the smoothing condition is satisfied:
\[\sum_i w_i \cdot (y_i - s(x_i))^2 \le s\]If None (default),
s = len(w)
is taken which should be a good value if1 / w[i]
is an estimate of the standard deviation ofy[i]
. If 0, the spline will interpolate through all data points.See
scipy.interpolate.UnivariateSpline
.
Estimated parameters
- Parameters:
spline_ (
scipy.interpolate.UnivariateSpline
) – spline function that can be applied tox
values
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') UnivariateSplineSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') UnivariateSplineSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- class cyclic_boosting.smoothing.onedim.WeightedMeanSmoother(prior_prediction=None)[source]#
Bases:
AbstractBinSmoother
,PredictingBinValueMixin
Smoother for one-dimensional bins regularizing values with uncertainties to the weighted mean or a user defined value.
- Parameters:
prior_prediction (float) – If the prior_prediction is specified, all values are regularized with it and not with the error weighted mean.
>>> y_for_smoother = np.array([0.9, 0.9, 0.9, 1.8, 1.8, 0.4, 0.4]) >>> X_for_smoother = np.c_[ ... [1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0], ... [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ... [0.05, 0.05, 0.05, 0.05, 0.15, 0.15, 0.05]] >>> from cyclic_boosting.smoothing.onedim import WeightedMeanSmoother >>> smoother = WeightedMeanSmoother() >>> smoother.fit(X_for_smoother, y_for_smoother) >>> smoother.smoothed_y_ array([ 0.90096366, 0.90096366, 0.90096366, 1.79077293, 1.723854 , 0.45467402, 0.40662518])
>>> y_for_smoother = np.array([-0.70710678, -0.70710678]) >>> X_for_smoother = np.c_[[0., 1.], [0.012]*2, [9.12870929]*2] >>> smoother = WeightedMeanSmoother() >>> smoother.fit(X_for_smoother, y_for_smoother) >>> smoother.smoothed_y_ array([-0.70710678, -0.70710678])
>>> y_for_smoother = np.array([-1, -1, -1, 1, 1]) >>> X_for_smoother = np.c_[ ... [1.0, 1.0, 1.0, 0.0, 0.0], ... [0.0, 0.0, 0.0, 0.0, 0.0], ... [0.5, 0.5, 0.5, 0.5, 0.5]] >>> smoother = WeightedMeanSmoother(prior_prediction=0) >>> smoother.fit(X_for_smoother, y_for_smoother) >>> smoothed_abs = (4. * 1 + 1 * 0) / (4 + 1) >>> np.testing.assert_allclose(smoother.smoothed_y_, ... y_for_smoother * smoothed_abs)
- set_fit_request(*, X_for_smoother: bool | None | str = '$UNCHANGED$') WeightedMeanSmoother #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
X_for_smoother (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_for_smoother
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') WeightedMeanSmoother #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
cyclic_boosting.smoothing.orthofit module#
- cyclic_boosting.smoothing.orthofit.cy_apply_orthogonal_poly_fit_equidistant(binnos, parameters, n_degrees)[source]#
- cyclic_boosting.smoothing.orthofit.cy_orthogonal_poly_fit_equidistant(binnos: Array(float64, 1, 'A', False, aligned=True), y_values: Array(float64, 1, 'A', False, aligned=True), y_errors: Array(float64, 1, 'A', False, aligned=True))[source]#
- cyclic_boosting.smoothing.orthofit.fit_orthogonal_poly_(x: Array(float64, 1, 'A', False, aligned=True), y: Array(float64, 1, 'A', False, aligned=True), weights: Array(float64, 1, 'A', False, aligned=True), parameters: Array(float64, 1, 'A', False, aligned=True)) float64 [source]#
Module contents#
Smoothers of target profiles and factor profiles or for the regularization of plots.
- class cyclic_boosting.smoothing.RegressionType(value)[source]#
Bases:
Enum
Type of regression that is supported by the smoother.
Three variants are supported:
- discontinuous: It cannot be interpolated between the values seen
by the smoother (e.g. the values are unordered labels). Therefore all values in predict are set to nan that are out of the bin boundries in the fit or where no fit events have been seen.
- interpolating: Interpolation is possible between the values seen by
the smoother. So only values above or below the bin boundries are critical. Therefore all values in predict are set to nan that are out of the bin boundries in the fit.
- extrapolating: Extrapolation allows arbitrary values independent of
the values seen in the fit. Therefore no restrictions apply.
- discontinuous = 'discontinuous'#
- extrapolating = 'extrapolating'#
- interpolating = 'interpolating'#