Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Scikit GradientBoostingClassifier won't let me use least squares regression?

Why could it be that

GradientBoostingClassifier(loss='ls')

fails with:

raise ValueError("``n_classes`` must be 1 for regression")
ValueError: ``n_classes`` must be 1 for regression

and it works perfectly with loss='deviance'?

I'm using scikit-learn-0.11 with scipy-0.11.0rc1 in Ubuntu 64 bits This happened classifying a dataset with binary class 'YES' 'NO'.

like image 391
user947468 Avatar asked Aug 30 '12 13:08

user947468


People also ask

How do I import GradientBoostingRegressor?

ensemble import GradientBoostingRegressor >>> from sklearn. model_selection import train_test_split >>> X, y = make_regression(random_state=0) >>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, random_state=0) >>> reg = GradientBoostingRegressor(random_state=0) >>> reg.

Can gradient boost be used for regression?

Gradient boosting can be used for regression and classification problems.


1 Answers

This is a bug in GradientBoostingClassifier. It shouldn't expose the least squares loss function for classification. Please use the "deviance" loss function instead.

Sorry for the inconveniences caused.

PS: If you really need least squared loss for classification please contact me and we can work on this feature for a future release.

like image 68
Peter Prettenhofer Avatar answered Sep 19 '22 12:09

Peter Prettenhofer