image_output_2.png image_output_1.png
from sklearn.utils import shuffle

import numpy as np

import pandas as pd

import pylab

data_file = '../input/Amazon_Unlocked_Mobile.csv'
data = pd.read_csv(data_file)

data_df = pd.DataFrame(data)

data_df = shuffle(data_df)

data_df = data_df.dropna()

info = pd.pivot_table(data_df, index=['Brand Name'], values=['Rating', 'Review Votes'], columns=[], aggfunc=[np.sum, np.mean], fill_value=0)
info = info.sort_values(by=('sum', 'Rating'), ascending=False)

corr_matrix = data_df.corr()
corr_matrix['Rating'].sort_values(ascending=False)

corr_matrix = data_df.corr()
corr_matrix['Price'].sort_values(ascending=False)

data_df = data_df.reset_index(drop=True)

temp_data = data_df[0:20000]

temp_data.shape

counter = 0
for i in range(0, 20000):
    if abs(temp_data['Rating'][i] - temp_data['SENTIMENT_VALUE'][i]) > 1:
        counter += 1

accuracy = (temp_data.shape[0] - counter) / temp_data.shape[0]

testing2 = pd.pivot_table(temp_data, index=['Brand Name'], values=['Rating', 'Review Votes', 'SENTIMENT_VALUE'], columns=[], aggfunc=[np.sum, np.mean], fill_value=0)
testing2 = testing2.sort_values(by=('sum', 'Rating'), ascending=False)

import pylab
names = testing2.index[:10]
y = testing2['sum', 'SENTIMENT_VALUE'][:10]
y2 = testing2['sum', 'Rating'][:10]
pylab.figure(figsize=(15, 7))
x = range(10)
pylab.subplot(2, 1, 1)
pylab.xticks(x, names)
pylab.ylabel('Summed Values')
pylab.title('Total Sum Values')
pylab.plot(x, y, 'r-', x, y2, 'b-')
pylab.legend(['SentimentValue', 'Rating'])
y_new = testing2['mean', 'SENTIMENT_VALUE'][:10]
y2_new = testing2['mean', 'Rating'][:10]
pylab.figure(figsize=(15, 7))
pylab.subplot(2, 1, 2)
pylab.xticks(x, names)
pylab.ylabel('Mean Values')
pylab.title('Mean Values')
pylab.plot(x, y_new, 'r-', x, y2_new, 'b-')
pylab.legend(['SentimentValue', 'Rating'])
pylab.show()