Python 3 - ValueError:无法将字符串转换为浮点数:'-'

时间:2021-04-23 07:42:21

标签: python-3.x pandas floating-point valueerror word-embedding

所以我正在从 xlsx 文件中读取数据,当我检查“features.dtypes”时所有值都是浮动的,但出现此错误:AttributeError: 'Series' object has no attribute 'reshape'

xl = pd.ExcelFile("2021we-train.xlsx") xl.sheet_names df = xl.parse("2021wordembeddingsv4-trim")

y = np.zeros([41+299]) y[0:41]=1

labels=y features=df.drop('id',axis=1)

train_features, test_features, train_labels, test_labels = train_test_split(features, labels) parameters = {'C': np.linspace(0.0001, 100, 20)} grid_search = GridSearchCV(LogisticRegression(), parameters) grid_search.fit(train_features, train_labels)

这是我得到的完整错误:

<块引用> <块引用>

----------------------------------------------- ---------------------------- ValueError 回溯(最近一次调用 最后)在 1 个参数 = {'C': np.linspace(0.0001, 100, 20)} 2 grid_search = GridSearchCV(LogisticRegression(), 参数) ----> 3 grid_search.fit(train_features, train_labels) 4 5 print('最佳参数:', grid_search.best_params_)

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/utils/validation.py 在inner_f(*args, **kwargs) 61 extra_args = len(args) - len(all_args) 62 如果 extra_args <= 0: ---> 63 返回 f(*args, **kwargs) 64 65 # extra_args > 0

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/model_selection/search.py 适合(自我,X,y,组,**fit_params) 878 refit_start_time = time.time() 第879话 --> 880 self.best_estimator.fit(X, y, **fit_params) 881 其他: 第882话

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/linear_model/_logistic.py 合身(自我,X,y,sample_weight)1342 _dtype = [np.float64,np.float32] 1343 -> 1344 X, y = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype, 1345 order="C",
第1346章 'liblinear')

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/base.py 在 _validate_data(self, X, y, reset, validate_separately, **check_params) 第431话 432 其他: --> 433 X, y = check_X_y(X, y, **check_params) 第434话 435

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/utils/validation.py 在inner_f(*args, **kwargs) 61 extra_args = len(args) - len(all_args) 62 如果 extra_args <= 0: ---> 63 返回 f(*args, **kwargs) 64 65 # extra_args > 0

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/utils/validation.py 在 check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, 复制、force_all_finite、ensure_2d、allow_nd、multi_output、 ensure_min_samples、ensure_min_features、y_numeric、estimator) 812引发ValueError(“y不能是None”) 813 --> 814 X = check_array(X, accept_sparse=accept_sparse, 第815话 816 dtype=dtype,order=order,copy=copy,

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/utils/validation.py 在inner_f(*args, **kwargs) 61 extra_args = len(args) - len(all_args) 62 如果 extra_args <= 0: ---> 63 返回 f(*args, **kwargs) 64 65 # extra_args > 0

~/anaconda3/envs/project1/lib/python3.9/site-packages/sklearn/utils/validation.py 在 check_array(数组,accept_sparse,accept_large_sparse,dtype, 订单、复制、force_all_finite、ensure_2d、allow_nd、 确保最小样本、确保最小特征、估计器) 614 array = array.astype(dtype,cast="unsafe",copy=False) 615 其他: --> 616 array = np.asarray(array, order=order, dtype=dtype) 第 617 章 618 raise ValueError("不支持复杂数据\n"

~/anaconda3/envs/project1/lib/python3.9/site-packages/numpy/core/_asarray.py 在 asarray(a, dtype, order, like) 100 return _asarray_with_like(a, dtype=dtype, order=order, like=like) 101 --> 102 返回数组(a, dtype, copy=False, order=order) 103 104

~/anaconda3/envs/project1/lib/python3.9/site-packages/pandas/core/generic.py 在 array(self, dtype) 1897 1898 def array(self, dtype=无)-> np.ndarray: -> 1899 返回 np.asarray(self._values, dtype=dtype) 1900 1901 def array_wrap(

~/anaconda3/envs/project1/lib/python3.9/site-packages/numpy/core/_asarray.py 在 asarray(a, dtype, order, like) 100 return _asarray_with_like(a, dtype=dtype, order=order, like=like) 101 --> 102 返回数组(a, dtype, copy=False, order=order) 103 104

ValueError: 无法将字符串转换为浮点数:'-'

0 个答案:

没有答案