Skip to content

AttributeError: 'LeastSquaresError' object has no attribute 'get_init_raw_predictions' #14076

@mgb1028

Description

@mgb1028

Description

Attribute error thrown when calling predict with GradientBoostedRegressor.

This is a model that has already been trained and that has been used before. I am trying to run some predictions on new data and this error arises. If I extract one of the estimators I can call predict.

Steps/Code to Reproduce

import pandas as pd
import numpy as np
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.externals import joblib

matrix = pd.read_feather(design_path)
matrix_oct_dic18 = matrix[(matrix.fechaAltaCliente >= '2018-10-01') & (matrix.fechaAltaCliente <= '2018-12-31')]
recommendation = matrix_oct_dic18[['pkprospecto'] + X_cols]
model = joblib.load(model_path)
y = model.predict(recommendation[X_cols])

Unfortunately I cannot share most of the code and data being used.

Here are the model specifications:
GradientBoostingRegressor(alpha=0.9, criterion='friedman_mse', init=None,
learning_rate=0.005, loss='ls', max_depth=3,
max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=1000,
n_iter_no_change=None, presort='auto',
random_state=None, subsample=1.0, tol=0.0001,
validation_fraction=0.1, verbose=0, warm_start=False)

Expected Results

No error is thrown.

Actual Results


AttributeError Traceback (most recent call last)
in
----> 1 y = model.predict(recommendation[X_cols])

/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/gradient_boosting.py in predict(self, X)
2530 X = check_array(X, dtype=DTYPE, order="C", accept_sparse='csr')
2531 # In regression we can directly return the raw value from the trees.
-> 2532 return self._raw_predict(X).ravel()
2533
2534 def staged_predict(self, X):

/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/gradient_boosting.py in _raw_predict(self, X)
1669 def _raw_predict(self, X):
1670 """Return the sum of the trees raw predictions (+ init estimator)."""
-> 1671 raw_predictions = self.raw_predict_init(X)
1672 predict_stages(self.estimators
, X, self.learning_rate,
1673 raw_predictions)

/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/gradient_boosting.py in raw_predict_init(self, X)
1663 dtype=np.float64)
1664 else:
-> 1665 raw_predictions = self.loss
.get_init_raw_predictions(
1666 X, self.init_).astype(np.float64)
1667 return raw_predictions

AttributeError: 'LeastSquaresError' object has no attribute 'get_init_raw_predictions'

Versions

System:
python: 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00) [GCC 7.3.0]
executable: /opt/conda/bin/python
machine: Linux-4.15.0-51-generic-x86_64-with-debian-buster-sid

BLAS:
macros:
lib_dirs:
cblas_libs: cblas

Python deps:
pip: 19.1.1
setuptools: 41.0.1
sklearn: 0.21.2
numpy: 1.16.4
scipy: 1.2.1
Cython: None
pandas: 0.24.2

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions