Dec-08-2020, 07:05 PM
#per SGD classifier i dati devono essere numerically encoded, not dict from sklearn.linear_model import SGDClassifier clf = SGDClassifier() clf.fit(X_train, y_train) train_score = clf.score(X_train, y_train) valid_score = clf.score(X_valid, y_valid)I get the following error:
Error:TypeError Traceback (most recent call last)
<ipython-input-10-a2f8bfb8f242> in <module>
2 from sklearn.linear_model import SGDClassifier
3 clf = SGDClassifier()
----> 4 clf.fit(X_train, y_train)
5 train_score = clf.score(X_train, y_train)
6 valid_score = clf.score(X_valid, y_valid)
~\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\linear_model\_stochastic_gradient.py in fit(self, X, y, coef_init, intercept_init, sample_weight)
726 loss=self.loss, learning_rate=self.learning_rate,
727 coef_init=coef_init, intercept_init=intercept_init,
--> 728 sample_weight=sample_weight)
729
730
~\AppData\Local\Programs\Python\Python37\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)
539 X, y = self._validate_data(X, y, accept_sparse='csr',
540 dtype=np.float64, order="C",
--> 541 accept_large_sparse=False)
542
543 # labels can be encoded as float, int, or string literals
~\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\base.py in _validate_data(self, X, y, reset, validate_separately, **check_params)
430 y = check_array(y, **check_y_params)
431 else:
--> 432 X, y = check_X_y(X, y, **check_params)
433 out = X, y
434
~\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
70 FutureWarning)
71 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72 return f(**kwargs)
73 return inner_f
74
~\AppData\Local\Programs\Python\Python37\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, estimator)
800 ensure_min_samples=ensure_min_samples,
801 ensure_min_features=ensure_min_features,
--> 802 estimator=estimator)
803 if multi_output:
804 y = check_array(y, accept_sparse='csr', force_all_finite=True,
~\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
70 FutureWarning)
71 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72 return f(**kwargs)
73 return inner_f
74
~\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator)
596 array = array.astype(dtype, casting="unsafe", copy=False)
597 else:
--> 598 array = np.asarray(array, order=order, dtype=dtype)
599 except ComplexWarning:
600 raise ValueError("Complex data not supported\n"
~\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order)
81
82 """
---> 83 return array(a, dtype, copy=False, order=order)
84
85
TypeError: float() argument must be a string or a number, not 'dict'
I believe that this is an error from using the wrong version of python. I use python 3.83 on Windows 10. I am ot sure how to fix it.Any help appreciated. Thanks in advance
Respectfully,
ErnestTBass