Python ValueError:无法将字符串转换为浮点:';Udah stres bgt muka Udah beruntusan';

Python ValueError:无法将字符串转换为浮点:';Udah stres bgt muka Udah beruntusan';,python,svm,Python,Svm,我试着做一个简单的分类 from sklearn.svm import SVC classifier = SVC(kernel = 'linear', random_state =0) classifier.fit(X_train, y_train) 当我尝试进行分类时,出现了以下错误: ValueError:无法将字符串转换为浮点:“Udah stres bgt muka Udah beruntusan” 这是我的值错误回溯 ValueError

我试着做一个简单的分类

from sklearn.svm import SVC 
classifier = SVC(kernel = 'linear', random_state =0) 
classifier.fit(X_train, y_train)
当我尝试进行分类时,出现了以下错误: ValueError:无法将字符串转换为浮点:“Udah stres bgt muka Udah beruntusan”

这是我的值错误回溯

ValueError                                Traceback (most recent call last)
<ipython-input-24-c2136a7032e7> in <module>
      2 from sklearn.svm import SVC
      3 classifier = SVC(kernel = 'linear', random_state =0)
----> 4 classifier.fit(X_train, y_train)

~\Anaconda3\lib\site-packages\sklearn\svm\base.py in fit(self, X, y, sample_weight)
    144         X, y = check_X_y(X, y, dtype=np.float64,
    145                          order='C', accept_sparse='csr',
--> 146                          accept_large_sparse=False)
    147         y = self._validate_targets(y)
    148 

~\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)
    717                     ensure_min_features=ensure_min_features,
    718                     warn_on_dtype=warn_on_dtype,
--> 719                     estimator=estimator)
    720     if multi_output:
    721         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)
    494             try:
    495                 warnings.simplefilter('error', ComplexWarning)
--> 496                 array = np.asarray(array, dtype=dtype, order=order)
    497             except ComplexWarning:
    498                 raise ValueError("Complex data not supported\n"

~\Anaconda3\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
    536 
    537     """
--> 538     return array(a, dtype, copy=False, order=order)
    539 
    540 

~\Anaconda3\lib\site-packages\pandas\core\series.py in __array__(self, dtype)
    946             warnings.warn(msg, FutureWarning, stacklevel=3)
    947             dtype = "M8[ns]"
--> 948         return np.asarray(self.array, dtype)
    949 
    950     # ----------------------------------------------------------------------
ValueError回溯(最近一次调用)
在里面
2从sklearn.svm导入SVC
3分类器=SVC(内核=线性,随机状态=0)
---->4.配合(X_系列、y_系列)
~\Anaconda3\lib\site packages\sklearn\svm\base.py合适(自身、X、y、样本重量)
144 X,y=check_X_y(X,y,dtype=np.64,
145订单'C',接受'U sparse='csr',
-->146接受_大_稀疏=假)
147 y=自我验证目标(y)
148
~\Anaconda3\lib\site packages\sklearn\utils\validation.py in check\u X\u y(X,y,accept\u sparse,accept\u large\u sparse,dtype,order,copy,force\u all\u finite,sure\u 2d,allow\n,multi\u output,sure\u samples,sure\u min\u features,y\u numeric,warn\u on\u dtype,assistor)
717确保最小特征=确保最小特征,
718 warn_on_dtype=warn_on_dtype,
-->719估计员=估计员)
720如果多输出:
721 y=检查数组(y,'csr',强制所有有限=真,确保2d=假,
检查数组中的~\Anaconda3\lib\site packages\sklearn\utils\validation.py(数组、接受稀疏、接受大稀疏、数据类型、顺序、复制、强制所有有限、确保2d、允许nd、确保最小样本、确保最小特征、警告数据类型、估计器)
494尝试:
495警告。simplefilter('error',ComplexWarning)
-->496数组=np.asarray(数组,dtype=dtype,order=order)
497除复杂警告外:
498 raise VALUERROR(“不支持复杂数据\n”
asarray中的~\Anaconda3\lib\site packages\numpy\core\numeric.py(a,数据类型,顺序)
536
537     """
-->538返回数组(a,数据类型,copy=False,order=order)
539
540
~\Anaconda3\lib\site packages\pandas\core\series.py在数组中(self,dtype)
946警告。警告(消息,未来警告,堆栈级别=3)
947 dtype=“M8[ns]”
-->948返回np.asarray(self.array,dtype)
949
950     # ----------------------------------------------------------------------

有办法解决这个问题吗?

错误是因为数据中存在
字符串
对象,计算机无法解释这些对象,因为它只能理解数字

尝试使用以下两种技术转换
category
string
类型数据

  • pd.get\u假人

  • LabelEncoder


请添加创建
X\u列车的代码。
。我尝试使用pd.get\u假人,但结果仍然是相同的错误