أعمل على مجموعة بيانات "داتاسيت" هي تغريدات تويتر، لذا قمت مبدأياً ببناء نموذج LogisticRegrission لكن لاأعلم سبب الخطأ التالي:
<class 'pandas.core.series.Series'>
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-20b55637dec5> in <module>
10 print(type(X_train))
11 clf = LogisticRegression()
---> 12 clf.fit(X_train, y_train)
~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py in fit(self, X, y, sample_weight)
1525
1526 X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
-> 1527 accept_large_sparse=solver != 'liblinear')
1528 check_classification_targets(y)
1529 self.classes_ = np.unique(y)
~\anaconda3\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)
753 ensure_min_features=ensure_min_features,
754 warn_on_dtype=warn_on_dtype,
--> 755 estimator=estimator)
756 if multi_output:
757 y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,
~\anaconda3\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, warn_on_dtype, estimator)
529 array = array.astype(dtype, casting="unsafe", copy=False)
530 else:
--> 531 array = np.asarray(array, order=order, dtype=dtype)
532 except ComplexWarning:
533 raise ValueError("Complex data not supported\n"
~\anaconda3\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
~\anaconda3\lib\site-packages\pandas\core\series.py in __array__(self, dtype)
752 dtype='datetime64[ns]')
753 """
--> 754 return np.asarray(self.array, dtype)
755
756 # ----------------------------------------------------------------------
~\anaconda3\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
~\anaconda3\lib\site-packages\pandas\core\arrays\numpy_.py in __array__(self, dtype)
182
183 def __array__(self, dtype=None) -> np.ndarray:
--> 184 return np.asarray(self._ndarray, dtype=dtype)
185
186 _HANDLED_TYPES = (np.ndarray, numbers.Number)
~\anaconda3\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
ValueError: could not convert string to float: 'قزم العهد'
الكود:
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
import pandas as pd
Data = pd.read_csv('D:/train.csv')
Data['Tweet'] =Data['Tweet'].astype(str)
data["Class"].replace({"abusive":0,"hate":0,"normal":1},inplace=True)
data = Data['Tweet']
label = Data["Class"]
X_train, X_test, y_train, y_test = train_test_split(data, label, test_size = 0.2, random_state = 2021)
clf = LogisticRegression()
clf.fit(X_train, y_train)