0

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 Answers1

0

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)
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
  • return lambda x: strip_accents(x.lower()) AttributeError: 'numpy.ndarray' object has no attribute 'lower' –  Aug 26 '17 at 09:41