Search code examples
machine-learningnlp

How to do a single value prediction in NLP


My dataset was restaurants review with two columns review and liked. Based on the review it shows if they liked the restaurant or not

I cleaned up the data in NLP as the first step.Then as second step used bag of words model as below.

from sklearn.feature_extraction.text import CountVectorizer

cv = CountVectorizer(max_features = 1500)

X = cv.fit_transform(corpus).toarray()

y = dataset.iloc[:, 1].values

This above gave X as 1500 columns with 0 and 1 with 1000 rows according to my dataset.

I predicted as below

y_pred = classifier.predict(X_test)

So now I have review as "Food was good",how do I predict if they like it or not.A single value to predict.

Please can you help me out.Please let me know if additional information is required.

Thanks


Solution

  • All you need is to apply cv.transform first just like so:

    >>> test = ['Food was good']
    >>> test_vec = cv.transform(test)
    >>> classifier.predict(test_vec)
    # returns predicted class