我正在尝试使用随机梯度下降来找到准确性。我正在关注官方页面中的文档,但是在运行代码时出现错误。这是我的代码:
from sklearn.linear_model import SGDClassifier, LinearRegression
from sklearn import metrics
lr = SGDClassifier(loss="log", penalty="l2", max_iter=200)
lr.fit(X_train, y_train)
这是错误:
/usr/local/lib/python3.7/dist-packages/sklearn/utils/validation.py:985: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-fddfb1f613fe> in <module>()
3 from sklearn import metrics
4 lr = SGDClassifier(loss="log", penalty="l2", max_iter=200)
----> 5 lr.fit(X_train, y_train)
3 frames
<__array_function__ internals> in unique(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/numpy/lib/arraysetops.py in _unique1d(ar, return_index, return_inverse, return_counts)
320 aux = ar[perm]
321 else:
--> 322 ar.sort()
323 aux = ar
324 mask = np.empty(aux.shape, dtype=np.bool_)
TypeError: '<' not supported between instances of 'str' and 'int'