前提・実現したいこと
達人データサイエンティストによる理論と実践の本を写経しているのですが、本の通りやっているのですが、valueerrorになってしまいます。お助け願います、、、
###エラーメッセージ
10-fold cross validation: --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-19-4f5b5db10c84> in <module>() 29 y=y_train, 30 cv=10, ---> 31 scoring='roc_auc', 32 ) 33 print("ROC AUC:%0.2f (+/- %0.2f) [%s]" % (scores.mean(),score.std(),label)) ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/model_selection/_validation.py in cross_val_score(estimator, X, y, groups, scoring, cv, n_jobs, verbose, fit_params, pre_dispatch) 340 n_jobs=n_jobs, verbose=verbose, 341 fit_params=fit_params, --> 342 pre_dispatch=pre_dispatch) 343 return cv_results['test_score'] 344 ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/model_selection/_validation.py in cross_validate(estimator, X, y, groups, scoring, cv, n_jobs, verbose, fit_params, pre_dispatch, return_train_score) 204 fit_params, return_train_score=return_train_score, 205 return_times=True) --> 206 for train, test in cv.split(X, y, groups)) 207 208 if return_train_score: ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py in __call__(self, iterable) 777 # was dispatched. In particular this covers the edge 778 # case of Parallel used with an exhausted iterator. --> 779 while self.dispatch_one_batch(iterator): 780 self._iterating = True 781 else: ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py in dispatch_one_batch(self, iterator) 623 return False 624 else: --> 625 self._dispatch(tasks) 626 return True 627 ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py in _dispatch(self, batch) 586 dispatch_timestamp = time.time() 587 cb = BatchCompletionCallBack(dispatch_timestamp, len(batch), self) --> 588 job = self._backend.apply_async(batch, callback=cb) 589 self._jobs.append(job) 590 ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/externals/joblib/_parallel_backends.py in apply_async(self, func, callback) 109 def apply_async(self, func, callback=None): 110 """Schedule a func to be run""" --> 111 result = ImmediateResult(func) 112 if callback: 113 callback(result) ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/externals/joblib/_parallel_backends.py in __init__(self, batch) 330 # Don't delay the application, to avoid keeping the input 331 # arguments in memory --> 332 self.results = batch() 333 334 def get(self): ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py in __call__(self) 129 130 def __call__(self): --> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items] 132 133 def __len__(self): ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/externals/joblib/parallel.py in <listcomp>(.0) 129 130 def __call__(self): --> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items] 132 133 def __len__(self): ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/model_selection/_validation.py in _fit_and_score(estimator, X, y, scorer, train, test, verbose, parameters, fit_params, return_train_score, return_parameters, return_n_test_samples, return_times, error_score) 456 estimator.fit(X_train, **fit_params) 457 else: --> 458 estimator.fit(X_train, y_train, **fit_params) 459 460 except Exception as e: ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/pipeline.py in fit(self, X, y, **fit_params) 248 Xt, fit_params = self._fit(X, y, **fit_params) 249 if self._final_estimator is not None: --> 250 self._final_estimator.fit(Xt, y, **fit_params) 251 return self 252 ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight) 1235 self.class_weight, self.penalty, self.dual, self.verbose, 1236 self.max_iter, self.tol, self.random_state, -> 1237 sample_weight=sample_weight) 1238 self.n_iter_ = np.array([n_iter_]) 1239 return self ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/svm/base.py in _fit_liblinear(X, y, C, fit_intercept, intercept_scaling, class_weight, penalty, dual, verbose, max_iter, tol, random_state, multi_class, loss, epsilon, sample_weight) 884 check_consistent_length(sample_weight, X) 885 --> 886 solver_type = _get_liblinear_solver_type(multi_class, penalty, loss, dual) 887 raw_coef_, n_iter_ = liblinear.train_wrap( 888 X, y_ind, sp.isspmatrix(X), solver_type, tol, bias, C, ~/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/sklearn/svm/base.py in _get_liblinear_solver_type(multi_class, penalty, loss, dual) 745 raise ValueError('Unsupported set of arguments: %s, ' 746 'Parameters: penalty=%r, loss=%r, dual=%r' --> 747 % (error_string, penalty, loss, dual)) 748 749 ValueError: Unsupported set of arguments: The combination of penalty='12' and loss='logistic_regression' is not supported, Parameters: penalty='12', loss='logistic_regression', dual=False
該当のソースコード
python
1from sklearn import datasets 2from sklearn.model_selection import train_test_split 3from sklearn.preprocessing import StandardScaler 4from sklearn.preprocessing import LabelEncoder 5iris=datasets.load_iris() 6X,y=iris.data[50:,[1,2]],iris.target[50:] 7le=LabelEncoder() 8y=le.fit_transform(y) 9 10 11X_train,X_test,y_train,y_test=\ 12 train_test_split(X,y,test_size=0.5,random_state=1,stratify=y) 13 14from sklearn.model_selection import cross_val_score 15from sklearn.linear_model import LogisticRegression 16from sklearn.tree import DecisionTreeClassifier 17from sklearn.neighbors import KNeighborsClassifier 18from sklearn.pipeline import Pipeline 19import numpy as np 20 21clf1=LogisticRegression(penalty='12', 22 C=0.001, 23 random_state=1) 24clf2=DecisionTreeClassifier(max_depth=1, 25 criterion='entropy', 26 random_state=0) 27clf3=KNeighborsClassifier(n_neighbors=1, 28 p=2, 29 metric='minkowski') 30pipe1=Pipeline([['sc',StandardScaler()], 31 ['clf',clf1]]) 32 33pipe3=Pipeline([['sc',StandardScaler()], 34 ['clf',clf3]]) 35 36clf_labels=['Logistic regression ','Decision tree','KNN'] 37print('10-fold cross validation:\n') 38for clf,label in zip([pipe1,clf2,pipe3],clf_labels): 39 scores=cross_val_score( 40 estimator=clf, 41 X=X_train, 42 y=y_train, 43 cv=10, 44 scoring='roc_auc', 45 ) 46 print("ROC AUC:%0.2f (+/- %0.2f) [%s]" % (scores.mean(),score.std(),label))
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/13 02:44