python 使用sk_learn 遇到 問題ValueError: Expected 2D array, got 1D array instead:


這里我找到我的問題是:



使用的是一個新的scikit學習版本,它拋出了一個錯誤,因為在新版本中,所有東西都必須是一個二維矩陣,甚至是一個列或行。

它甚至說:用數組來重塑你的數據。如果您的數據有一個單獨的特性或數組,那么重構(-1,1)。重構(1,-1)如果它包含一個單一的樣本


這是在git上面看到的一個國際友人的解答。

原文,如下:

I think you're using a new scikit-learn version and it's throwing an error because in the new version everything has to be a 2d matrix, even a single column or row.


It even says: Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.


Have you tried this on your y column?

我遇到的就是這個問題,因為我使用的sklearn 是anaconda的3.5版本,應該是最新版本,所以出現了這個問題吧

然后我們來看看解決問題的方法:

調用 xx.reshape(1,-1)

可以使用,本人親測

即可將其轉為二維數組

各位加油!

有人問起怎么調用了,這里我說下  ,直接用需要修改的 數組名.reshape(1,-1) 即可



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM