Count vectorizer ValueError: Expected 2-dimensional array, got 1

505 views Asked by At

I have an error message here:

ValueError: Expected 2-dimensional array, got 1 But it seems like my variables are all 2d already. This is how my variables look like: http://www.oldschool-samp.com/slike/?v=variables.png

#read preprocessed data
traindata = ast.literal_eval(open('pretprocesirano.txt').read())
testdata = ast.literal_eval(open('pretprocesiranoTEST.py').read())

testdata=np.array(testdata).reshape(-1, 1)
label_train=np.array(label_train).reshape(-1, 1)
label_test=np.array(label_test).reshape(-1, 1)

cv=CountVectorizer(tokenizer=None,analyzer ='word',encoding='utf-8')
traindataCV= cv.fit_transform(traindata).toarray().reshape(-1,1)

#NaiveBayes
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()
1

There are 1 answers

1
MaxU - stand with Ukraine On

your traindata seems to be a Vanilla Python list (1D array), so try this:

traindata = np.array(ast.literal_eval(open('pretprocesirano.txt').read())) \
              .reshape(-1, 1)
testdata = np.array(ast.literal_eval(open('pretprocesiranoTEST.py').read())) \
             .reshape(-1, 1)