You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Custom loss functions for GradientBoostingRegressor/Classifier and HistGradientBoostingRegressor/Classifier #17659
changed the title [-]Custom loss functions for GradientBoostingRegressor/Classifier and HistGradientBoostingRegressor/Classifier [/-][+][Feature Request] Custom loss functions for GradientBoostingRegressor/Classifier and HistGradientBoostingRegressor/Classifier [/+]on Jun 22, 2020
See how it's inheriting from ForestClassifier? Right there in the class definition. Click that word to jump to it's parent definition.
See how this new object is inheriting from ClassifierMixin? Click that.
See how the bottom of that ClassifierMixin class says this?
from .metrics import accuracy_score
return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
That's your model being trained on accuracy. You need to inject at this point if you want to train your model to be a "recall model" or a "precision model" or whatever model. This accuracy metric is baked into SKlearn. Some day, a better man than I will make this a parameter which models accept, however in the mean time, you gotta go into your sklearn installation, and tweak this accuracy_score to be whatever you want.
Activity
[-]Custom loss functions for GradientBoostingRegressor/Classifier and HistGradientBoostingRegressor/Classifier [/-][+][Feature Request] Custom loss functions for GradientBoostingRegressor/Classifier and HistGradientBoostingRegressor/Classifier [/+]thomasjpfan commentedon Jun 22, 2020
We opened using custom loss functions in for
HistGradientBoostingin #16908Support for this feature is summarized here: #15841 (comment)
zachmayer commentedon Jun 22, 2020
Oh awesome! I'm sorry I missed that, that's very cool!
Sandy4321 commentedon Jun 27, 2021
is it possible to add custom loss function to classification tree as well?
https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html?highlight=tree#sklearn.tree.DecisionTreeClassifier
Sandy4321 commentedon Jun 27, 2021
people really need it
https://stackoverflow.com/questions/54267745/implementing-custom-loss-function-in-scikit-learn
It's tricky, but you can do it...
Open up your classifier. Let's use an RFC for example: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html
click [source]
See how it's inheriting from ForestClassifier? Right there in the class definition. Click that word to jump to it's parent definition.
See how this new object is inheriting from ClassifierMixin? Click that.
See how the bottom of that ClassifierMixin class says this?
from .metrics import accuracy_score
return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
That's your model being trained on accuracy. You need to inject at this point if you want to train your model to be a "recall model" or a "precision model" or whatever model. This accuracy metric is baked into SKlearn. Some day, a better man than I will make this a parameter which models accept, however in the mean time, you gotta go into your sklearn installation, and tweak this accuracy_score to be whatever you want.
NicolasHug commentedon Jun 28, 2021
@Sandy4321 please see #15841 (comment). The instructions copied pasted from SO above are incorrect.