2016-10-22 32 views
-1

我使用了python 2.7和sklearn 1.8。然後我使用1d數組創建2d數組。在我的Python代碼中出現錯誤「ValueError:發現輸入變量的樣本數量不一致:[16,8760]」

x=np.array([a,b,c,d...]) 

那樣(A,B,C,d ..是一維數組)

y=np.array(arr) 

ARR也1D陣列

model = GaussianNB() 
model.fit(x,y) 

其給我一個此錯誤

File "E:/python/read2.py", line 73, in <module> 
    model.fit(x,y) 
    File "C:\Python27\lib\site-packages\sklearn\naive_bayes.py", line 182, in fit 
    X, y = check_X_y(X, y) 
    File "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 531, in check_X_y 
    check_consistent_length(X, y) 
    File "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 181, in check_consistent_length 
    " samples: %r" % [int(l) for l in lengths]) 
ValueError: Found input variables with inconsistent numbers of samples: [16, 8760] 

x.shape =>(16,8760) ys高原肺水腫=>(8760)

請需要幫助..

+0

'fit'的幫助對於2個輸入的所需形狀有什麼幫助?你瞭解'x'和'y'的形狀嗎? – hpaulj

回答

0

來源:http://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.GaussianNB.html#sklearn.naive_bayes.GaussianNB.fit

X : array-like, shape (n_samples, n_features) 
Training vectors, where n_samples is the number of samples and n_features is the number of features. 
y : array-like, shape (n_samples,) 

你的價值觀:

x.shape => (16, 8760) y.shape => (8760,) 

它看起來像8760米的樣品,16個功能?如果是這樣x.T可能會工作。

+0

謝謝你的迴應,是的,我讀過,我知道x形狀是錯誤的,這就是爲什麼我解釋我如何創建x.thank你。 –

相關問題