text_plain_output_1.png
from sklearn.feature_extraction.text import CountVectorizer

from sklearn.linear_model import LogisticRegression

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('../input/Amazon_Unlocked_Mobile.csv')

df.dropna(inplace=True)

df = df[df['Rating'] != 3]

df['Positively Rated'] = np.where(df['Rating'] > 3, 1, 0)

X_train.shape

from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer().fit(X_train)

len(vect.get_feature_names())

vect.get_feature_names()[0:10]

vect.get_feature_names()[::3000]

X_train_vectorized = vect.transform(X_train)
X_train_vectorized

X_train_vectorized.shape

from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train_vectorized, y_train)

pred = model.predict(vect.transform(X_test))

feature_names = np.array(vect.get_feature_names())
sorted_coef_index = model.coef_[0].argsort()

print('Smallest Coefs:\n{}\n'.format(feature_names[sorted_coef_index[:10]]))
print('Largest Coefs: \n{}'.format(feature_names[sorted_coef_index[:-11:-1]]))