前提
初心者の質問恐れ入ります。
Kaggleの問題でロジスティック回帰モデルを初めて構築しているのですが、(おそらく)型の違いでエラーが発生してしまっております。
実現したいこと
エラーが解消され、ロジスティック回帰モデルが構築できること
発生している問題・エラーメッセージ
TypeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_27632\1366492367.py in <module> 8 9 # 学習 ---> 10 clf.fit(X_train, y_train) ~\anaconda3\lib\site-packages\sklearn\linear_model\_stochastic_gradient.py in fit(self, X, y, coef_init, intercept_init, sample_weight) 881 Returns an instance of self. 882 """ --> 883 return self._fit( 884 X, 885 y, ~\anaconda3\lib\site-packages\sklearn\linear_model\_stochastic_gradient.py in _fit(self, X, y, alpha, C, loss, learning_rate, coef_init, intercept_init, sample_weight) 647 sample_weight=None, 648 ): --> 649 self._validate_params() 650 if hasattr(self, "classes_"): 651 # delete the attribute otherwise _partial_fit thinks it's not the first call ~\anaconda3\lib\site-packages\sklearn\linear_model\_stochastic_gradient.py in _validate_params(self, for_partial_fit) 135 if self.early_stopping and for_partial_fit: 136 raise ValueError("early_stopping should be False with partial_fit") --> 137 if self.max_iter is not None and self.max_iter <= 0: 138 raise ValueError("max_iter must be > zero. Got %f" % self.max_iter) 139 if not (0.0 <= self.l1_ratio <= 1.0): TypeError: '<=' not supported between instances of 'str' and 'int'
該当のソースコード
python(anaconda3)
1# インスタンス生成 2clf = SGDClassifier(loss = 'log', 3 penalty = 'none', 4 max_iter = '10000', 5 random_state = 1234, 6 fit_intercept = True 7 ) 8 9# 学習 10clf.fit(X_train, y_train)
試したこと
データの型は以下のとおりです。ターゲットはfloatです。
ホールドアウト
y_train = train.iloc[:,0]
X_train = train.iloc[:,1:]
print('y============')
y_train.info()
print('x============')
X_train.info()
y============
<class 'pandas.core.series.Series'>
Int64Index: 370448 entries, 0 to 378660
Series name: state
Non-Null Count Dtype
370448 non-null float64
dtypes: float64(1)
memory usage: 5.7 MB
x============
<class 'pandas.core.frame.DataFrame'>
Int64Index: 370448 entries, 0 to 378660
Columns: 191 entries, backers to main_category_Theater
dtypes: float64(3), uint8(188)
memory usage: 77.7 MB
補足情報(FW/ツールのバージョンなど)
conda 22.9.0
Name Version Build Channel
anaconda 2022.10 py39_0
あなたの回答
tips
プレビュー