前提・実現したいこと
「東京大学のデータサイエンティスト育成講座」を使って、
現在機械学習の学習をしています。
その中でリッジ回帰の練習をしていたところ、
以下のエラーが起きました。
発生している問題・エラーメッセージ
ValueError Traceback (most recent call last) <ipython-input-42-849a09ff5163> in <module> 13 14 for model in [linear, ridge]: ---> 15 model.fit(X_train, y_train) 16 print('{}(train):{:.6f}'.format(model.__class__.__name__, model.score(X_train, y_train))) 17 print('{}(test):{:.6f}'.format(model.__class__.__name__, model.score(X_test, y_test))) c:\users\jupyter-notebook\lib\site-packages\sklearn\linear_model\base.py in fit(self, X, y, sample_weight) 461 n_jobs_ = self.n_jobs 462 X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'], --> 463 y_numeric=True, multi_output=True) 464 465 if sample_weight is not None and np.atleast_1d(sample_weight).ndim > 1: c:\users\jupyter-notebook\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator) 725 _assert_all_finite(y) 726 if y_numeric and y.dtype.kind == 'O': --> 727 y = y.astype(np.float64) 728 729 check_consistent_length(X, y) ValueError: could not convert string to float: '?'
該当のソースコード
Python
1#class for ridge regression 2from sklearn.linear_model import Ridge 3from sklearn.model_selection import train_test_split 4 5#divide into training data and test data 6X = auto.drop('price', axis=1) 7y = auto['price'] 8X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0) 9 10#construct and assess the model 11linear = LinearRegression() 12ridge = Ridge(random_state=0) 13 14for model in [linear, ridge]: 15 model.fit(X_train, y_train) 16 print('{}(train):{:.6f}'.format(model.__class__.__name__, model.score(X_train, y_train))) 17 print('{}(test):{:.6f}'.format(model.__class__.__name__, model.score(X_test, y_test)))
試したこと
astypeで全てのデータ型をfloat32に変えようとしたのですが、
同じエラーが起きました。
何卒宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/16 08:37
2019/08/16 08:43
2019/08/19 00:28