[英]Why am I getting value error and extra args in python for machine learning
I have problem with my Jupyter.我的 Jupyter 有问题。
I don't know if my problem is my code or something else.我不知道我的问题是我的代码还是其他问题。
nsamples, nx, ny = prediction_space.shape
d2_prediction_space = prediction_space.reshape((nsamples,nx*ny))
y_pred= reg.predict(prediction_space)
and here is the error这是错误
ValueError Traceback (most recent call last)
<ipython-input-31-3f4eb9eb6fc8> in <module>
1 nsamples, nx, ny = prediction_space.shape
2 d2_prediction_space = prediction_space.reshape((nsamples,nx*ny))
----> 3 y_pred= reg.predict(prediction_space)
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model\_base.py in predict(self, X)
236 Returns predicted values.
237 """
--> 238 return self._decision_function(X)
239
240 _preprocess_data = staticmethod(_preprocess_data)
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model\_base.py in _decision_function(self, X)
218 check_is_fitted(self)
219
--> 220 X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
221 return safe_sparse_dot(X, self.coef_.T,
222 dense_output=True) + self.intercept_
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
---> 63 return f(*args, **kwargs)
64
65 # extra_args > 0
C:\ProgramData\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, estimator)
714 "into decimal numbers with dtype='numeric'") from e
715 if not allow_nd and array.ndim >= 3:
--> 716 raise ValueError("Found array with dim %d. %s expected <= 2."
717 % (array.ndim, estimator_name))
718
ValueError: Found array with dim 3. Estimator expected <= 2.
Since you can run through this line因为你可以通过这条线
nsamples, nx, ny = prediction_space.shape
This implies that your prediction_space
is three dimensional, but from the error message it seems reg.predict
takes only a two dimensional input, so this is the problem.这意味着您的
prediction_space
是三维的,但从错误消息来看, reg.predict
似乎只需要二维输入,所以这就是问题所在。
I think you tried to reshape your prediction_space
into two dimensional我认为你试图将你的
prediction_space
重塑为二维
d2_prediction_space = prediction_space.reshape((nsamples,nx*ny))
Are you supposed to run reg.predict
on d2_prediction_space
instead of prediction_space
?您是否应该在
d2_prediction_space
而不是prediction_space
上运行reg.predict
? Like this?像这样?
y_pred= reg.predict(d2_prediction_space)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.