2016-10-22 2 views
-1

Ich habe Python 2.7 und sklearn 1.8 verwendet.Fehler in meinem Python-Code "ValueError: Eingangsvariablen mit inkonsistenten Zahlen von Samples gefunden: [16, 8760]"

import numpy as np 
from sklearn.naive_bayes import GaussianNB 

dann habe ich 2d-Array mit 1d-Arrays erstellt.

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

wie das (a, b, c, d .. sind 1D-Arrays)

y=np.array(arr) 

arr auch 1D-Array

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

seine gib mir eine diesen Fehler

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 hape => (8760,)

bitte Hilfe benötigen ..

+0

Was sagt die Hilfe für 'fit' über die erforderlichen Formen der 2 Eingänge? Verstehst du die Formen von 'x' und' y'? – hpaulj

Antwort

0

Von: 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,) 

Ihre Werte:

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

, die wie 8760 Proben aussieht, 16 Funktionen? Wenn ja, könnte x.T funktionieren.

+0

danke für deine antwort, ja ich lese das und ich weiß x form ist falsch deswegen erkläre ich wie ich x.thank erstellt habe. –

Verwandte Themen