簡體   English   中英

為什么我在 python 中收到用於機器學習的值錯誤和額外參數

[英]Why am I getting value error and extra args in python for machine learning

我的 Jupyter 有問題。

我不知道我的問題是我的代碼還是其他問題。

    nsamples, nx, ny = prediction_space.shape
    d2_prediction_space = prediction_space.reshape((nsamples,nx*ny))
    y_pred= reg.predict(prediction_space)

這是錯誤

    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.

因為你可以通過這條線

nsamples, nx, ny = prediction_space.shape

這意味着您的prediction_space是三維的,但從錯誤消息來看, reg.predict似乎只需要二維輸入,所以這就是問題所在。

我認為你試圖將你的prediction_space重塑為二維

d2_prediction_space = prediction_space.reshape((nsamples,nx*ny))

您是否應該在d2_prediction_space而不是prediction_space上運行reg.predict 像這樣?

y_pred= reg.predict(d2_prediction_space)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM