Repository navigation
Conversation
jnothman
left a comment
There was a problem hiding this comment.
Would it possible to see something more refactored and conventionalised, like:
def fit(X, y):
self.classes_ = check_classes(self.classes, y, multioutput=False)
and sometimes
self.classes_, label_encoders = check_classes(self.classes, y, multioutput=True, return_encoder=True)
?
| (classes, ndim, str(classes_k), | ||
| classes_k.dtype.name)) | ||
| if unq.size != np.asarray(classes_k).size: | ||
| raise ValueError("Classses parameter should contain all unique" |
| """LAD updates terminal regions to median estimates. """ | ||
| terminal_region = np.where(terminal_regions == leaf)[0] | ||
| sample_weight = sample_weight.take(terminal_region, axis=0) | ||
| diff = y.take(terminal_region, axis=0) - pred.take(terminal_region, axis=0) |
There was a problem hiding this comment.
Please please please do not litter your work with unrelated changes. This makes it so much harder to review, particularly when it's a big patch. It also introduces unnecessary merge conflicts into other PRs modifying this code. We know the repo contains non-PEP8 code. Once it's merged we leave it.
There was a problem hiding this comment.
Actually I had a chat with @amueller about this earlier and he suggested that its a good idea to fix the non-pep8 code first whenever I start modify a file.
But I see your point. I'm sorry but I can't really do anything about it now. I'll make these changes in separate PRs in future.
There was a problem hiding this comment.
should be pretty straight-forward to undo....
There was a problem hiding this comment.
should be pretty straight-forward to undo....
you mean manually inspect all the changes and then undo? or is there a better way?
i just thought i could better use time in doing other classifiers than undoing all pep8 fixes?
There was a problem hiding this comment.
You can do git checkout filename master and use git gui or a diff tool to look at the diff and commit.
| permutation_test_score(clf, X_df, y_ser) | ||
|
|
||
|
|
||
| def test_cross_val_score_labels_paramter(): |
| # case when not set, infer from y | ||
| if self.classes is None: | ||
| # np.unique should not be used here becasue unique_labels performs | ||
| # some checkes as well |
jnothman
left a comment
There was a problem hiding this comment.
Brief comments on estimator checks.
| yield check_classes_parameter_sorted_unique | ||
|
|
||
| if hasattr(estimator, 'predict_proba'): | ||
| yield check_classes_parameter_predict_proba |
There was a problem hiding this comment.
I'm not sure why you want a separate test for predict_proba and decision_function. Can they be merged? You also need to check that the value of classes is copied to classes_ when present.
There was a problem hiding this comment.
there are a couple of reasons why:
- in a binary classification case, predict_proba returns 2 vectors and decision function only 1.
- when passing extra classes, not present in the data, then probabilities for those classes should be 0, but what should be the decision function for those classes? it depends on the estimator I suppose so the checks are slightly different for both cases.
i can create if else structure in the check, but i thought it might be cleaner code to keep them separate.
i'll add the check you suggested. we do something similar in scorer but it should be here as well.
| pred0 = clf.fit(X, y).predict_proba(X) | ||
|
|
||
| params['classes'] = [1, 2] | ||
| clf.set_params(**params) |
There was a problem hiding this comment.
This requires the estimator to have a classes attribute and in turn creates a backwards incompatibility for users of check_estimator. At least for a couple of versions, we should only warn if a classifier providing predict_proba, predict_log_proba or decision_function lacks a classes parameter.
There was a problem hiding this comment.
right now, these checks are only for the classifiers which i've updated. but I think you're talking about user-defined estimators. would it work that we should just perform this check if classes is present as a parameter in the estimator? will we be specifying that classes parameter should be present in all user-defined classifiers?
There was a problem hiding this comment.
I'm actually not sure if we should require that. It's a good question. I think for now it would be fine if we skip the test if classes is not a parameter.
|
merge conflict and failing test. Do you want reviews? |
the merge conflict came up today, probably because of some recent merge. failing test is just in gradientboosting.py which I'm trying to fix now. I wanted a review of the overall idea, I'm good with @jnothman's points now, I can work on them. |
|
given all the problems we run into with this, I'm not entirely sure any more if this is the right solution. Maybe stop work on it for now and let's step back and discuss in #8100. |
|
I've been trying to wrap my head around GBM. I suspect the error is because Binomial Deviance uses LogOddsEstimator for initialization which sets priors as 0 if 2 classes are equal in number. On the other hand, Multinomial Deviance uses PriorProbabilityEstimator which will set priors as 0.5 each if 2 classes are same. So I don't think they will give the same residuals and final trees if we try to model 2 classes using Multinomial Deviance. I even checked by having a y with 3 classes and then comparing the models without setting classes and another with classes set as [1,2,3,4]. Even then the results are not the same because the negative gradient is: |
|
This would need a fresh start if there's interest, and probably better with a smaller PRs than a large one. |
A WIP PR, ref: #8100 and #9290
Added classes to following classifiers:
To be done: