python - sci-kit learn: Reshape your data either using X.reshape(-1, 1) -


i'm training python (2.7.11) classifier text classification , while running i'm getting deprecated warning message don't know line in code causing it! error/warning. however, code works fine , give me results...

\appdata\local\enthought\canopy\user\lib\site-packages\sklearn\utils\validation.py:386: deprecationwarning: passing 1d arrays data deprecated in 0.17 , willraise valueerror in 0.19. reshape data either using x.reshape(-1, 1) if data has single feature or x.reshape(1, -1) if contains single sample.

my code:

def main():     data = []     folds = 10     ex = [ [] x in range(0,10)]     results = []     i,f in enumerate(sys.argv[1:]):         data.append(csv.dictreader(open(f,'r'),delimiter='\t'))     f in data:                i,datum in enumerate(f):             ex[i % folds].append(datum)     #print ex     held_out in range(0,folds):         l = []         cor = []         l_test = []         cor_test = []         vec = []         vec_test = []          i,fold in enumerate(ex):             line in fold:                 if == held_out:                     l_test.append(line['label'].rstrip("\n"))                     cor_test.append(line['text'].rstrip("\n"))                 else:                     l.append(line['label'].rstrip("\n"))                     cor.append(line['text'].rstrip("\n"))          vectorizer = countvectorizer(ngram_range=(1,1),min_df=1)         x = vectorizer.fit_transform(cor)         c in cor:                     tmp = vectorizer.transform([c]).toarray()             vec.append(tmp[0])         c in cor_test:                     tmp = vectorizer.transform([c]).toarray()             vec_test.append(tmp[0])          clf = multinomialnb()         clf .fit(vec,l)         result = accuracy(l_test,vec_test,clf)         print result  if __name__ == "__main__":     main() 

any idea line raises warning? issue running code different data sets gives me same exact accuracy, , can't figure out cases this? if want use model in python process, looked @ documentation , found example of using pickle library, not joblib. so, tried following same code, gave me errors:

clf = joblib.load('model.pkl')  pred = clf.predict(vec); 

also, if data csv file format: "lable \t text \n" should in lable column in test data?

thanks in advance

your 'vec' input clf.fit(vec,l) .fit needs of type [[]], not []. quirk forget when fit models.

just adding set of square brackets should trick!


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -