Error while using GridSearchCV.
Hi, I'm trying to use GridSearchCV to tune the parameters for DecisionTreeRegressor. I'm using sklearn 0.18.1 I'm getting the following error: ---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-36-192f7c286a58> in <module>() 1 # Fit the training data to the model using grid search----> 2 reg = fit_model(X_train, y_train) 3 4 # Produce the value for 'max_depth' 5 print "Parameter 'max_depth' is {} for the optimal model.".format(reg.get_params()['max_depth']) <ipython-input-35-500141c331d9> in fit_model(X, y) 11 12 # Create cross-validation sets from the training data---> 13 cv_sets = ShuffleSplit(X.shape[0], n_splits = 10, test_size = 0.20, random_state = 0) 14 15 # TODO: Create a decision tree regressor object TypeError: __init__() got multiple values for keyword argument 'n_splits' -- *Thanks,* *Shubham Singh Tomar* *Autodidact24.github.io <http://Autodidact24.github.io>*
Shubham, the definition of ShuffleSplit.__init__ is ShuffleSplit(n_splits=10, test_size=0.1, train_size=None, random_state=None) you are passing the n_split parameter twice (once named and once as the first parameter), as the exception that you getting says, -- Roman On 07/03/17 14:24, Shubham Singh Tomar wrote:
Hi,
I'm trying to use GridSearchCV to tune the parameters for DecisionTreeRegressor. I'm using sklearn 0.18.1
I'm getting the following error:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-36-192f7c286a58> in <module>() 1 # Fit the training data to the model using grid search----> 2reg = fit_model(X_train, y_train)3 4 # Produce the value for 'max_depth'5 print "Parameter 'max_depth' is {} for the optimal model.".format(reg.get_params()['max_depth'])<ipython-input-35-500141c331d9> in fit_model(X, y) 11 12 # Create cross-validation sets from the training data---> 13cv_sets = ShuffleSplit(X.shape[0], n_splits = 10, test_size = 0.20, random_state = 0)14 15 # TODO: Create a decision tree regressor objectTypeError: __init__() got multiple values for keyword argument 'n_splits'
-- *Thanks,* *Shubham Singh Tomar* *Autodidact24.github.io <http://Autodidact24.github.io>*
_______________________________________________ scikit-learn mailing list scikit-learn@python.org https://mail.python.org/mailman/listinfo/scikit-learn
Hey Shubham, I am a project reviewer at Udacity. This code seems to be part of one of our projects (P1 - Boston Housing <https://github.com/WittmannF/Machine_Learning-Boston_Housing/blob/master/bos...>). I think that you have updated the old module sklearn.cross_validation to the module sklearn.model_detection, is that correct? If yes, then you should also update the parameters in ShuffleSplit to match with this new version (check the docs <http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.Shu...>). Try to update ShuffleSplit to the following line of code: cv_sets = ShuffleSplit(n_splits=10, test_size=0.2, random_state=0) I hope that helps! Feel free to send me a PM. On Tue, Mar 7, 2017 at 10:24 AM, Shubham Singh Tomar < tomarshubham24@gmail.com> wrote:
Hi,
I'm trying to use GridSearchCV to tune the parameters for DecisionTreeRegressor. I'm using sklearn 0.18.1
I'm getting the following error:
---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-36-192f7c286a58> in <module>() 1 # Fit the training data to the model using grid search----> 2 reg = fit_model(X_train, y_train) 3 4 # Produce the value for 'max_depth' 5 print "Parameter 'max_depth' is {} for the optimal model.".format(reg.get_params()['max_depth']) <ipython-input-35-500141c331d9> in fit_model(X, y) 11 12 # Create cross-validation sets from the training data---> 13 cv_sets = ShuffleSplit(X.shape[0], n_splits = 10, test_size = 0.20, random_state = 0) 14 15 # TODO: Create a decision tree regressor object TypeError: __init__() got multiple values for keyword argument 'n_splits'
-- *Thanks,* *Shubham Singh Tomar* *Autodidact24.github.io <http://Autodidact24.github.io>*
_______________________________________________ scikit-learn mailing list scikit-learn@python.org https://mail.python.org/mailman/listinfo/scikit-learn
-- Fernando Marcos Wittmann
Hi, guys! Thanks for the responses. @Fernando: Yes, this code is, in fact, part of Udacity's Boston Housing project. I'm currently working on my MLE Nanodegree. I was able to modify the code to go with *sklearn.model_selection*, as you suggested. And, it's great to see you help Udacity students here as well :) Do you think we should update the code and project description in main Udacity repository to support the newer sklearn versions? On Wed, Mar 8, 2017 at 2:32 AM, Fernando Marcos Wittmann < fernando.wittmann@gmail.com> wrote:
Hey Shubham,
I am a project reviewer at Udacity. This code seems to be part of one of our projects (P1 - Boston Housing <https://github.com/WittmannF/Machine_Learning-Boston_Housing/blob/master/bos...>). I think that you have updated the old module sklearn.cross_validation to the module sklearn.model_detection, is that correct? If yes, then you should also update the parameters in ShuffleSplit to match with this new version (check the docs <http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.Shu...>). Try to update ShuffleSplit to the following line of code:
cv_sets = ShuffleSplit(n_splits=10, test_size=0.2, random_state=0)
I hope that helps! Feel free to send me a PM.
On Tue, Mar 7, 2017 at 10:24 AM, Shubham Singh Tomar < tomarshubham24@gmail.com> wrote:
Hi,
I'm trying to use GridSearchCV to tune the parameters for DecisionTreeRegressor. I'm using sklearn 0.18.1
I'm getting the following error:
---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-36-192f7c286a58> in <module>() 1 # Fit the training data to the model using grid search----> 2 reg = fit_model(X_train, y_train) 3 4 # Produce the value for 'max_depth' 5 print "Parameter 'max_depth' is {} for the optimal model.".format(reg.get_params()['max_depth']) <ipython-input-35-500141c331d9> in fit_model(X, y) 11 12 # Create cross-validation sets from the training data---> 13 cv_sets = ShuffleSplit(X.shape[0], n_splits = 10, test_size = 0.20, random_state = 0) 14 15 # TODO: Create a decision tree regressor object TypeError: __init__() got multiple values for keyword argument 'n_splits'
-- *Thanks,* *Shubham Singh Tomar* *Autodidact24.github.io <http://Autodidact24.github.io>*
_______________________________________________ scikit-learn mailing list scikit-learn@python.org https://mail.python.org/mailman/listinfo/scikit-learn
--
Fernando Marcos Wittmann
_______________________________________________ scikit-learn mailing list scikit-learn@python.org https://mail.python.org/mailman/listinfo/scikit-learn
-- *Thanks,* *Shubham Singh Tomar* *Autodidact24.github.io <http://Autodidact24.github.io>*
participants (3)
-
Fernando Marcos Wittmann -
Roman Yurchak -
Shubham Singh Tomar