ValueError Traceback (most recent call last) Input In [35], in <cell line: 2>() 1 scores, values = [], [] 2 for education in education_list: ----> 3 score, y = predict(data, education) 4 scores.append(score) 5 values.append(y) Input In [32], in predict(data, education) 13 # model 训练 14 model = LinearRegression() ---> 15 model.fit(x, y) 16 # model 预测 17 X = [[i] for i in range(11)] File D:\big data\lib\site-packages\sklearn\linear_model\_base.py:662, in LinearRegression.fit(self, X, y, sample_weight) 658 n_jobs_ = self.n_jobs 660 accept_sparse = False if self.positive else ["csr", "csc", "coo"] --> 662 X, y = self._validate_data( 663 X, y, accept_sparse=accept_sparse, y_numeric=True, multi_output=True 664 ) 666 if sample_weight is not None: 667 sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) File D:\big data\lib\site-packages\sklearn\base.py:581, in BaseEstimator._validate_data(self, X, y, reset, validate_separately, **check_params) 579 y = check_array(y, **check_y_params) 580 else: --> 581 X, y = check_X_y(X, y, **check_params) 582 out = X, y 584 if not no_val_X and check_params.get("ensure_2d", True): File D:\big data\lib\site-packages\sklearn\utils\validation.py:964, 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) 961 if y is None: 962 raise ValueError("y cannot be None") --> 964 X = check_array( 965 X, 966 accept_sparse=accept_sparse, 967 accept_large_sparse=accept_large_sparse, 968 dtype=dtype, 969 order=order, 970 copy=copy, 971 force_all_finite=force_all_finite, 972 ensure_2d=ensure_2d, 973 allow_nd=allow_nd, 974 ensure_min_samples=ensure_min_samples, 975 ensure_min_features=ensure_min_features, 976 estimator=estimator, 977 ) 979 y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric) 981 check_consistent_length(X, y) File D:\big data\lib\site-packages\sklearn\utils\validation.py:746, 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) 744 array = array.astype(dtype, casting="unsafe", copy=False) 745 else: --> 746 array = np.asarray(array, order=order, dtype=dtype) 747 except ComplexWarning as complex_warning: 748 raise ValueError( 749 "Complex data not supported\n{}\n".format(array) 750 ) from complex_warning ValueError: could not convert string to float: '若干'
时间: 2024-04-26 19:20:51 浏览: 141
Python解析json之ValueError: Expecting property name enclosed in double quotes: line 1 column 2(char 1)
这个错误通常表示你的代码中有一个字符串无法转换为浮点数,具体来说,出现了无法将“若干”字符串转换为浮点数的错误。请检查你的代码中的数据类型是否正确,确保所有数据都是浮点数或可以转换为浮点数的格式。你需要将数据集中的“若干”字符串转换为数字或删除这些数据。如果你不能删除这些数据,请使用数据清洗技术将它们转换为浮点数或其他可以使用的格式。
阅读全文