boost_loss.regression package
- class boost_loss.regression.AsymmetricCompositeLoss(loss_pred_less: LossBase, loss_pred_greater: LossBase)[source]
Bases:
LossBaseAsymmetric composite loss function. The loss function is loss_pred_less if y_true < y_pred, otherwise loss_pred_greater.
- grad_hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) tuple[numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]], numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]]][source]
Gradient and hessian of loss function. Override this method if you want to calculate both gradient and hessian at the same time.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient and hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
tuple[NDArray, NDArray]
- loss(y_true: NDArray, y_pred: NDArray) float | NDArray[source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.AsymmetricLoss(loss: LossBase, t: float = 0.5)[source]
Bases:
AsymmetricCompositeLossAsymmetric loss function. The loss function is loss * (1 - t) if y_true < y_pred, otherwise loss * t. Generalized from quantile loss (pinball loss, check loss, etc.) and expectile loss.
- class boost_loss.regression.ExpectileLoss(t: float = 0.5)[source]
Bases:
AsymmetricLoss[Expectile](https://sites.google.com/site/csphilipps/expectiles) loss function. - Expectile is a conditional mean if observations in [μ_τ, ∞) are τ/(1 - τ) times more likely than the original distribution. - Expectiles are not always quantiles of F. - Expectile loss is more smooth than quantile loss.
\[\tau \int_{-\infty}^{\mu_\tau} (y - \mu_\tau) dF(y) = (1 - \tau) \int_{\mu_\tau}^{\infty} (y - \mu_\tau) dF(y)\]
- class boost_loss.regression.FairLoss(c: float = 1.0)[source]
Bases:
LossBaseFair loss = c^2/2 * (abs(y_true - y_pred) - c * log(1 + abs(y_true - y_pred)/c))
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.GammaLoss[source]
Bases:
LossBaseGamma loss = y_true / y_pred - log(y_true / y_pred) - 1
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.HuberLoss(delta: float = 1.0)[source]
Bases:
LossBaseHuber loss = 0.5 (y_true - y_pred)^2 if |y_true - y_pred| <= delta else delta * (|y_true - y_pred| - 0.5 * delta)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.L1Loss(*, divide_n_loss: bool = False, divide_n_grad: bool = True)[source]
Bases:
LNLossL1 loss = |y_true - y_pred|.
- divide_n_grad: bool
Whether to divide the gradient by n. Generally True is used.
- divide_n_loss: bool
Whether to divide the loss by n. Generally False is used.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- n: float
The exponent of the loss.
- class boost_loss.regression.L2Loss(*, divide_n_loss: bool = False, divide_n_grad: bool = True)[source]
Bases:
LNLossL2 loss = |y_true - y_pred|^2
- divide_n_grad: bool
Whether to divide the gradient by n. Generally True is used.
- divide_n_loss: bool
Whether to divide the loss by n. Generally False is used.
- n: float
The exponent of the loss.
- class boost_loss.regression.LNLoss(n: float, divide_n_loss: bool = False, divide_n_grad: bool = True)[source]
Bases:
LossBaseLNLoss = |y_true - y_pred|^n - x < 1 is not recommended because the loss is not convex. - x >> 2 is not recommended because the gradient is too steep.
- divide_n_grad: bool
Whether to divide the gradient by n. Generally True is used.
- divide_n_loss: bool
Whether to divide the loss by n. Generally False is used.
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- n: float
The exponent of the loss.
- property name: str
Name of loss function.
- Returns:
Snake case of class name. e.g. LogCoshLoss -> log_cosh_loss.
- Return type:
str
- class boost_loss.regression.LogCoshLoss[source]
Bases:
LossBaseLogCosh loss = log(cosh(y_true - y_pred))
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.LogLoss[source]
Bases:
LossBaseLog loss = log(1 + exp(-y_true * y_pred))
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.MAPELoss[source]
Bases:
LossBaseMean absolute percentage error loss = abs(y_true - y_pred) / y_true
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.MSLELoss[source]
Bases:
LossBaseMean squared logarithmic error loss = (log(1 + y_true) - log(1 + y_pred))^2
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.PoissonLoss[source]
Bases:
LossBasePoisson loss = y_pred - y_true * log(y_pred)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.QuantileLoss(t: float = 0.5)[source]
Bases:
AsymmetricLoss[Quantile](https://en.wikipedia.org/wiki/Quantile) loss function.
- class boost_loss.regression.SMAPELoss[source]
Bases:
LossBaseSymmetric mean absolute percentage error loss = abs(y_true - y_pred) / ((abs(y_true) + abs(y_pred))/2)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.TweedieLoss(p: float = 1.5)[source]
Bases:
LossBaseTweedie loss = -y_true * y_pred^(2-p) / (2-p) + y_pred^(1-p) / (1-p)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.VarianceEstimator(estimator: Any, loss: LossBase, *, ts: int | Sequence[float], n_jobs: int | None = 1, verbose: int = 0, random_state: int | None = None, m_type: Literal['mean', 'median'] = 'mean', var_type: Literal['var', 'std', 'range', 'mae', 'mse'] = 'std', apply_objective: bool = True, apply_eval_metric: bool = True, target_transformer: BaseEstimator | Any | None = None, recursive: bool = True, recursive_strict: bool = False)[source]
Bases:
BaseEstimatorEstimator that estimates the distribution by simply using multiple estimators with different t. Compared to [NGBoost](https://stanfordmlgroup.github.io/projects/ngboost/) or [CatBoost’s Uncertainty](https://catboost.ai/en/docs/references/uncertainty), this estimator is much slower and does not support “natural gradient”, but does not require any assumption on the distribution.
Note that NGBoost supports [any user-defineddistribution](https://stanfordmlgroup.github.io/ngboost/5-dev.html) # noqa but it has to be defined beforehand.
NGBoost requires mean estimator and log standard deviation estimator to be trained simultaneously, which is very difficult to implement in sklearn / lightgbm / xgboost. (Need to start and stop fitting per iteration) Consider change Base parameter in NGBoost. (See https://github.com/stanfordmlgroup/ngboost/issues/250)
- fit(X: Any, y: Any, **fit_params: Any) Self[source]
Fit each estimator with different t.
- Parameters:
X (Any) – The training input samples.
y (Any) – The target values.
- Returns:
Fitted estimator.
- Return type:
Self
- Raises:
RuntimeError – Raises if joblib fails to return the results.
- m_type: Literal['mean', 'median']
- predict(X: Any, type_: Literal['mean', 'median', 'var', 'std', 'range', 'mae', 'mse'] | None = None, return_std: Literal[False] = False, **predict_params: Any) ndarray[Any, dtype[Any]][source]
- predict(X: Any, type_: tuple[Literal['mean', 'median'], Literal['var', 'std', 'range', 'mae', 'mse']] | None = None, return_std: Literal[True] = False, **predict_params: Any) tuple[numpy.ndarray[Any, numpy.dtype[Any]], numpy.ndarray[Any, numpy.dtype[Any]]]
Returns predictions of the ensemble.
- Parameters:
X (Any) – X
type (Literal['mean', 'median', 'var', 'std', 'range', 'mae', 'mse'], optional) – Type of the prediction, by default None If None, self.m_type is used.
return_std (bool, optional) – Whether to return a tuple of (predictions, standard deviation), by default False
**predict_params (Any) – The parameters to be passed to predict method of each estimator.
- Returns:
Predictions of the ensemble with shape (n_samples,)
- Return type:
NDArray[Any]
- Raises:
ValueError – When type_ is not supported.
- predict_raw(X: Any, **predict_params: Any) ndarray[Any, dtype[Any]][source]
Returns raw predictions of each estimator.
- Parameters:
X (Any) – X
**predict_params (Any) – The parameters to be passed to predict method of each estimator.
- Returns:
Raw predictions of each estimator with shape (n_estimators, n_samples)
- Return type:
NDArray[Any]
- predict_var(X: Any, type_: Literal['var', 'std', 'range', 'mae', 'mse'] | None = None, **predict_params: Any) NDArray[Any][source]
Returns variance of the ensemble.
- Parameters:
X (Any) – X
type (Literal['var', 'std', 'range', 'mae', 'mse'], optional) – Type of the variance, by default None If None, self.var_type is used.
**predict_params (Any) – The parameters to be passed to predict method of each estimator.
- Returns:
Variance of the ensemble with shape (n_samples,)
- Return type:
NDArray[Any]
- set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$', type_: bool | None | str = '$UNCHANGED$') VarianceEstimator
Request metadata passed to the
predictmethod.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 topredictif 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:
return_std (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
return_stdparameter inpredict.type (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
type_parameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- ts_: Sequence[float]
- var_type: Literal['var', 'std', 'range', 'mae', 'mse']
Submodules
boost_loss.regression.asymmetric module
- class boost_loss.regression.asymmetric.AsymmetricCompositeLoss(loss_pred_less: LossBase, loss_pred_greater: LossBase)[source]
Bases:
LossBaseAsymmetric composite loss function. The loss function is loss_pred_less if y_true < y_pred, otherwise loss_pred_greater.
- grad_hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) tuple[numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]], numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]]][source]
Gradient and hessian of loss function. Override this method if you want to calculate both gradient and hessian at the same time.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient and hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
tuple[NDArray, NDArray]
- loss(y_true: NDArray, y_pred: NDArray) float | NDArray[source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.asymmetric.AsymmetricLoss(loss: LossBase, t: float = 0.5)[source]
Bases:
AsymmetricCompositeLossAsymmetric loss function. The loss function is loss * (1 - t) if y_true < y_pred, otherwise loss * t. Generalized from quantile loss (pinball loss, check loss, etc.) and expectile loss.
- class boost_loss.regression.asymmetric.ExpectileLoss(t: float = 0.5)[source]
Bases:
AsymmetricLoss[Expectile](https://sites.google.com/site/csphilipps/expectiles) loss function. - Expectile is a conditional mean if observations in [μ_τ, ∞) are τ/(1 - τ) times more likely than the original distribution. - Expectiles are not always quantiles of F. - Expectile loss is more smooth than quantile loss.
\[\tau \int_{-\infty}^{\mu_\tau} (y - \mu_\tau) dF(y) = (1 - \tau) \int_{\mu_\tau}^{\infty} (y - \mu_\tau) dF(y)\]
- class boost_loss.regression.asymmetric.QuantileLoss(t: float = 0.5)[source]
Bases:
AsymmetricLoss[Quantile](https://en.wikipedia.org/wiki/Quantile) loss function.
boost_loss.regression.regression module
- class boost_loss.regression.regression.FairLoss(c: float = 1.0)[source]
Bases:
LossBaseFair loss = c^2/2 * (abs(y_true - y_pred) - c * log(1 + abs(y_true - y_pred)/c))
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.GammaLoss[source]
Bases:
LossBaseGamma loss = y_true / y_pred - log(y_true / y_pred) - 1
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.HuberLoss(delta: float = 1.0)[source]
Bases:
LossBaseHuber loss = 0.5 (y_true - y_pred)^2 if |y_true - y_pred| <= delta else delta * (|y_true - y_pred| - 0.5 * delta)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.L1Loss(*, divide_n_loss: bool = False, divide_n_grad: bool = True)[source]
Bases:
LNLossL1 loss = |y_true - y_pred|.
- divide_n_grad: bool
Whether to divide the gradient by n. Generally True is used.
- divide_n_loss: bool
Whether to divide the loss by n. Generally False is used.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- n: float
The exponent of the loss.
- class boost_loss.regression.regression.L2Loss(*, divide_n_loss: bool = False, divide_n_grad: bool = True)[source]
Bases:
LNLossL2 loss = |y_true - y_pred|^2
- divide_n_grad: bool
Whether to divide the gradient by n. Generally True is used.
- divide_n_loss: bool
Whether to divide the loss by n. Generally False is used.
- n: float
The exponent of the loss.
- class boost_loss.regression.regression.LNLoss(n: float, divide_n_loss: bool = False, divide_n_grad: bool = True)[source]
Bases:
LossBaseLNLoss = |y_true - y_pred|^n - x < 1 is not recommended because the loss is not convex. - x >> 2 is not recommended because the gradient is too steep.
- divide_n_grad: bool
Whether to divide the gradient by n. Generally True is used.
- divide_n_loss: bool
Whether to divide the loss by n. Generally False is used.
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- n: float
The exponent of the loss.
- property name: str
Name of loss function.
- Returns:
Snake case of class name. e.g. LogCoshLoss -> log_cosh_loss.
- Return type:
str
- class boost_loss.regression.regression.LogCoshLoss[source]
Bases:
LossBaseLogCosh loss = log(cosh(y_true - y_pred))
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.LogLoss[source]
Bases:
LossBaseLog loss = log(1 + exp(-y_true * y_pred))
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.MAPELoss[source]
Bases:
LossBaseMean absolute percentage error loss = abs(y_true - y_pred) / y_true
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.MSLELoss[source]
Bases:
LossBaseMean squared logarithmic error loss = (log(1 + y_true) - log(1 + y_pred))^2
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.PoissonLoss[source]
Bases:
LossBasePoisson loss = y_pred - y_true * log(y_pred)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.SMAPELoss[source]
Bases:
LossBaseSymmetric mean absolute percentage error loss = abs(y_true - y_pred) / ((abs(y_true) + abs(y_pred))/2)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
- class boost_loss.regression.regression.TweedieLoss(p: float = 1.5)[source]
Bases:
LossBaseTweedie loss = -y_true * y_pred^(2-p) / (2-p) + y_pred^(1-p) / (1-p)
- grad(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 1st order derivative (gradient) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The gradient of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- hess(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
The 2nd order derivative (hessian) of loss w.r.t. y_pred.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The hessian of loss function. 1-D array with shape (n_samples,).
- Return type:
NDArray
- Raises:
NotImplementedError – If not implemented.
- loss(y_true: ndarray[Any, dtype[ScalarType]], y_pred: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]][source]
Loss function. If 1-D array is returned, the mean of array is calculated. Return 1-D array if possible in order to utilize weights in the dataset if available.
- Parameters:
y_true (NDArray) – The true target values.
y_pred (NDArray) – The predicted target values.
- Returns:
The loss function. 1-D array with shape (n_samples,) or float.
- Return type:
NDArray | float
- Raises:
NotImplementedError – If not implemented.
boost_loss.regression.sklearn module
- class boost_loss.regression.sklearn.VarianceEstimator(estimator: Any, loss: LossBase, *, ts: int | Sequence[float], n_jobs: int | None = 1, verbose: int = 0, random_state: int | None = None, m_type: Literal['mean', 'median'] = 'mean', var_type: Literal['var', 'std', 'range', 'mae', 'mse'] = 'std', apply_objective: bool = True, apply_eval_metric: bool = True, target_transformer: BaseEstimator | Any | None = None, recursive: bool = True, recursive_strict: bool = False)[source]
Bases:
BaseEstimatorEstimator that estimates the distribution by simply using multiple estimators with different t. Compared to [NGBoost](https://stanfordmlgroup.github.io/projects/ngboost/) or [CatBoost’s Uncertainty](https://catboost.ai/en/docs/references/uncertainty), this estimator is much slower and does not support “natural gradient”, but does not require any assumption on the distribution.
Note that NGBoost supports [any user-defineddistribution](https://stanfordmlgroup.github.io/ngboost/5-dev.html) # noqa but it has to be defined beforehand.
NGBoost requires mean estimator and log standard deviation estimator to be trained simultaneously, which is very difficult to implement in sklearn / lightgbm / xgboost. (Need to start and stop fitting per iteration) Consider change Base parameter in NGBoost. (See https://github.com/stanfordmlgroup/ngboost/issues/250)
- fit(X: Any, y: Any, **fit_params: Any) Self[source]
Fit each estimator with different t.
- Parameters:
X (Any) – The training input samples.
y (Any) – The target values.
- Returns:
Fitted estimator.
- Return type:
Self
- Raises:
RuntimeError – Raises if joblib fails to return the results.
- m_type: Literal['mean', 'median']
- predict(X: Any, type_: Literal['mean', 'median', 'var', 'std', 'range', 'mae', 'mse'] | None = None, return_std: Literal[False] = False, **predict_params: Any) ndarray[Any, dtype[Any]][source]
- predict(X: Any, type_: tuple[Literal['mean', 'median'], Literal['var', 'std', 'range', 'mae', 'mse']] | None = None, return_std: Literal[True] = False, **predict_params: Any) tuple[numpy.ndarray[Any, numpy.dtype[Any]], numpy.ndarray[Any, numpy.dtype[Any]]]
Returns predictions of the ensemble.
- Parameters:
X (Any) – X
type (Literal['mean', 'median', 'var', 'std', 'range', 'mae', 'mse'], optional) – Type of the prediction, by default None If None, self.m_type is used.
return_std (bool, optional) – Whether to return a tuple of (predictions, standard deviation), by default False
**predict_params (Any) – The parameters to be passed to predict method of each estimator.
- Returns:
Predictions of the ensemble with shape (n_samples,)
- Return type:
NDArray[Any]
- Raises:
ValueError – When type_ is not supported.
- predict_raw(X: Any, **predict_params: Any) ndarray[Any, dtype[Any]][source]
Returns raw predictions of each estimator.
- Parameters:
X (Any) – X
**predict_params (Any) – The parameters to be passed to predict method of each estimator.
- Returns:
Raw predictions of each estimator with shape (n_estimators, n_samples)
- Return type:
NDArray[Any]
- predict_var(X: Any, type_: Literal['var', 'std', 'range', 'mae', 'mse'] | None = None, **predict_params: Any) NDArray[Any][source]
Returns variance of the ensemble.
- Parameters:
X (Any) – X
type (Literal['var', 'std', 'range', 'mae', 'mse'], optional) – Type of the variance, by default None If None, self.var_type is used.
**predict_params (Any) – The parameters to be passed to predict method of each estimator.
- Returns:
Variance of the ensemble with shape (n_samples,)
- Return type:
NDArray[Any]
- set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$', type_: bool | None | str = '$UNCHANGED$') VarianceEstimator
Request metadata passed to the
predictmethod.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 topredictif 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:
return_std (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
return_stdparameter inpredict.type (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
type_parameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- ts_: Sequence[float]
- var_type: Literal['var', 'std', 'range', 'mae', 'mse']