create auto-detection of classifier and regressor for tree-based transformers - #353
Conversation
|
PR is working on issue #189 - automate detection of classifier and regressor for tree-based transformers |
|
hi @solegalli, A couple of questions in how to approach this issue:
Gracias! Feliz ano! |
|
My idea was to use a function from sklearn that evaluates the target and decides if it is binary or continuous. I found this function: type_of_target The thing is, that function works well for binary or continuous variables (floats). But it is unclear for targets with just integers. If a target has integers only, say 0,1,2,3,4, then the So I am not sure this issue makes sense :/ I've seen a user inadvertently train a regression model on a binary target. Maybe instead of modifying the functionality too much, we could use the Unless you can find another function that we can rely more on? |
|
If user sets If user sets Could you dig a bit in sklearn to see if there is something similar for continuous targets? |
|
Hi @solegalli, Am I correct in that the hypothetical If so, one approach is that we could create an init param called What do you think? For example, variable "A" has 1,000 observations and I'll continue to search for a prebuilt function. However, I have not found one yet. Feliz ano! |
|
Hi @Morgan-Sell I looked as well, I don't think sklearn check for continuous targets. We should not add any more parameters to the init file. If regression is true, we just check that the target is not binary with the type_of_target. If regression is false, we use the check_classification target function from sklearn to check the target. That's all. If target is discrete, we leave it to the user's judgement. |
…nd correspodning docstrings
|
Hi @solegalli, I believe I implemented necessary changes - both in the init() and the test file. Lmk what you think! |
solegalli
left a comment
There was a problem hiding this comment.
Hi @Morgan-Sell
Thank you so much for the code provided.
We should not rename parameters that already exist (regression, is_regression), because that creates backward incompatibility. And we avoid that as much as we can.
The target is only passed during fit, so the target checks should be moved to the fit method.
Also, try if self.regression is True instead of just if self.regression. It is more explicit. If regression was a list or a string, it would be true in the latter, but false in the former.
Thank you!
|
I implemented your suggested edits. Hopefully, we're good to go! |
It is so that If I am using version 1.1, and I have a lot of code prepared already, and then I download version 1.2, I want to be able to run my code as is, without changing param names, order or having to now add the param because the default value has changed.. The things that you changed will affect those users who do not pass the parameter names to the class, so instead of |
|
I think we just need to add this to the tree discretizer, right? Almost there :p |
|
Are you "suggesting" that we refactor the init params names/order for the DecisionTreeDiscretiser class? ;) I never changed the init params names/order for the DecisionTreeDiscretiser class. Example code: That's |
|
We need to check that the target coincides with what the user passes in the param regression also in the tree discretizer, using the functions from sklearn |
|
Will return to resolve the test failures. |
…est_error_when_regression_is_false_and_target_is_continuous() to be compatible w/ df_discretise()
|
Hi @solegalli, I implemented the new code and the respective tests. However, I'm receiving the following error due to the ValueError that is raised in fit():
I traced the error back to test_all_transformers() in test_check_estimator_discretisers(), which uses sklearn's check_estimator(). I'm a bit thrown off by The error message that corresponds to the ValueError is I believe the ValueError message matches the stated criteria in the AssertionError. Do you have any ideas? |
solegalli
left a comment
There was a problem hiding this comment.
Hi @Morgan-Sell
Thank you for the changes!
Regarding the first error, my suggestion would be to add regression=False to the transformer in this line and see if that resolves the issue and does not break it somewhere else. That would be the quickest (if it works)
Also, there is a style check failing:
tests/test_discretisation/test_decision_tree_discretiser.py:121:62: W292 no newline at end of file
See as well my comments below.
Thank you!
| def test_encoding_method_param(df_enc): | ||
| # defaults | ||
| encoder = DecisionTreeEncoder() | ||
| encoder = DecisionTreeEncoder(regression=False) |
There was a problem hiding this comment.
why do we need this change?
| # ordered encoding | ||
| encoder = DecisionTreeEncoder(encoding_method="ordered") | ||
| encoder = DecisionTreeEncoder( | ||
| encoding_method="ordered", regression=False |
There was a problem hiding this comment.
why do we need this change?
| with pytest.raises(ValueError): | ||
| encoder = DecisionTreeEncoder(encoding_method="other") | ||
| encoder = DecisionTreeEncoder( | ||
| encoding_method="other", regression=False |
There was a problem hiding this comment.
why do we need this change?
|
Hi @solegalli, Of course, your suggestion worked! Why did adding I also removed the Se acabo este PR?! |
specify default parameters for readability
the check_estimator from sklearn creates some random X and y to test the transformers. In this case, it was creating a binary y, so because our default parameter was regression=True, and the transformer does not accept binary targets as per the changes in this PR, it was raising and error and did not allow sklearn to continue with the tests. changing regression=False, allowed the tests on the transformer to proceed with a binary target. |
|
Hi @Morgan-Sell I made some cosmetic changes, and then broke the tests somewhere, so I had to fix and made a PR to your repo. If you merge there, then we can merge and close here. Thank you so much for the great work!!! |
|
|
||
| return df | ||
|
|
||
|
|
There was a problem hiding this comment.
Why do is df_discterise() in the test file and not the conftest file?
There was a problem hiding this comment.
in the general conftest we put dataframes that are used for testing across modules, by more than 1 transformer.
This df you created was exclusive to test this discretizer. So it is better to put it in the test file it is used.
fixes tests after cosmetic changes
No description provided.