text_plain_output_2.png text_plain_output_1.png image_output_1.png
from sklearn.feature_extraction.text import CountVectorizer

from sklearn.model_selection import GridSearchCV

from sklearn.model_selection import train_test_split

from sklearn.naive_bayes import MultinomialNB

import numpy as np # linear algebra

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

import time

import time

data = pd.read_pickle('../input/515k-reviews-after-preprocessing/After_filling_Nans')

df = pd.read_pickle('../input/515k-reviews-after-preprocessing/After preprocessing')

summary = np.array(df.Summary)
score = df['score'].values

import time
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split
start_time = time.time()
best_params = []
parameters = {'alpha': [i for i in range(1, 100, 10)]}
acc = []
score = list(score)
for i in range(2000, 14000, 1000):
    vec = CountVectorizer(max_features=i)
    data = vec.fit_transform(summary)
    nb = MultinomialNB()
    clf = GridSearchCV(nb, parameters, cv=5)
    x_train, x_test, y_train, y_test = train_test_split(data, score, test_size=0.3, random_state=42)
    clf.fit(x_train, y_train)
    acc.append(100.0 * sum(clf.predict(x_test)) / len(clf.predict(x_test)))
    best_params.append(clf.best_params_)
    vec = 0
    data = 0
print('--- %s seconds ---' % (time.time() - start_time))