|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
变量如图片
代码如下:
- from sklearn import linear_model
- model = linear_model.LinearRegression()
- model.fit(X,y)
复制代码
报错如下:
- TypeError Traceback (most recent call last)
- Cell In[140], line 3
- 1 from sklearn import linear_model
- 2 model = linear_model.LinearRegression()
- ----> 3 model.fit(X,y)
- File ~\anaconda3\Lib\site-packages\sklearn\base.py:1474, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs)
- 1467 estimator._validate_params()
- 1469 with config_context(
- 1470 skip_parameter_validation=(
- 1471 prefer_skip_nested_validation or global_skip_validation
- 1472 )
- 1473 ):
- -> 1474 return fit_method(estimator, *args, **kwargs)
- File ~\anaconda3\Lib\site-packages\sklearn\linear_model\_base.py:578, in LinearRegression.fit(self, X, y, sample_weight)
- 574 n_jobs_ = self.n_jobs
- 576 accept_sparse = False if self.positive else ["csr", "csc", "coo"]
- --> 578 X, y = self._validate_data(
- 579 X, y, accept_sparse=accept_sparse, y_numeric=True, multi_output=True
- 580 )
- 582 has_sw = sample_weight is not None
- 583 if has_sw:
- File ~\anaconda3\Lib\site-packages\sklearn\base.py:650, in BaseEstimator._validate_data(self, X, y, reset, validate_separately, cast_to_ndarray, **check_params)
- 648 y = check_array(y, input_name="y", **check_y_params)
- 649 else:
- --> 650 X, y = check_X_y(X, y, **check_params)
- 651 out = X, y
- 653 if not no_val_X and check_params.get("ensure_2d", True):
- File ~\anaconda3\Lib\site-packages\sklearn\utils\validation.py:1263, 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)
- 1258 estimator_name = _check_estimator_name(estimator)
- 1259 raise ValueError(
- 1260 f"{estimator_name} requires y to be passed, but the target y is None"
- 1261 )
- -> 1263 X = check_array(
- 1264 X,
- 1265 accept_sparse=accept_sparse,
- 1266 accept_large_sparse=accept_large_sparse,
- 1267 dtype=dtype,
- 1268 order=order,
- 1269 copy=copy,
- 1270 force_all_finite=force_all_finite,
- 1271 ensure_2d=ensure_2d,
- 1272 allow_nd=allow_nd,
- 1273 ensure_min_samples=ensure_min_samples,
- 1274 ensure_min_features=ensure_min_features,
- 1275 estimator=estimator,
- 1276 input_name="X",
- 1277 )
- 1279 y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric, estimator=estimator)
- 1281 check_consistent_length(X, y)
- File ~\anaconda3\Lib\site-packages\sklearn\utils\validation.py:833, 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, input_name)
- 734 """Input validation on an array, list, sparse matrix or similar.
- 735
- 736 By default, the input is checked to be a non-empty 2D array containing
- (...)
- 830 array([[1, 2, 3], [4, 5, 6]])
- 831 """
- 832 if isinstance(array, np.matrix):
- --> 833 raise TypeError(
- 834 "np.matrix is not supported. Please convert to a numpy array with "
- 835 "np.asarray. For more information see: "
- 836 "https://numpy.org/doc/stable/reference/generated/numpy.matrix.html"
- 837 )
- 839 xp, is_array_api_compliant = get_namespace(array)
- 841 # store reference to original array to check if copy is needed when
- 842 # function returns
- TypeError: np.matrix is not supported. Please convert to a numpy array with np.asarray. For more information see: https://numpy.org/doc/stable/reference/generated/numpy.matrix.html
复制代码 |
-
|