In [1]:
import graphlab
In [2]:
products = graphlab.SFrame('amazon_baby.gl/')
In [3]:
products.head()
Out[3]:
In [4]:
products['word_count'] = graphlab.text_analytics.count_words(products['review'])
In [5]:
products.head()
Out[5]:
In [6]:
graphlab.canvas.set_target('ipynb')
In [7]:
products['name'].show()
In [8]:
giraffe_reviews = products[products['name'] == 'Vulli Sophie the Giraffe Teether']
In [9]:
len(giraffe_reviews)
Out[9]:
In [12]:
giraffe_reviews['rating'].show(view='Categorical')
In [13]:
products['rating'].show(view='Categorical')
In [14]:
#ignore all 3* reviews
products = products[products['rating'] != 3]
In [15]:
#positive sentiment = 4* or 5* reviews
products['sentiment'] = products['rating'] >=4
In [16]:
products.head()
Out[16]:
In [17]:
train_data,test_data = products.random_split(.8, seed=0)
In [18]:
sentiment_model = graphlab.logistic_classifier.create(train_data,
target='sentiment',
features=['word_count'],
validation_set=test_data)
In [19]:
sentiment_model.evaluate(test_data, metric='roc_curve')
Out[19]:
In [23]:
graphlab.canvas.set_target('browser')
sentiment_model.show(view='Evaluation')
In [20]:
giraffe_reviews['predicted_sentiment'] = sentiment_model.predict(giraffe_reviews, output_type='probability')
In [21]:
giraffe_reviews.head()
Out[21]:
In [22]:
giraffe_reviews = giraffe_reviews.sort('predicted_sentiment', ascending=False)
In [24]:
giraffe_reviews.head()
Out[24]:
In [25]:
giraffe_reviews[0]['review']
Out[25]:
In [26]:
giraffe_reviews[1]['review']
Out[26]:
In [27]:
giraffe_reviews[-1]['review']
Out[27]:
In [28]:
giraffe_reviews[-2]['review']
Out[28]:
In [25]:
selected_words = ['awesome', 'great', 'fantastic', 'amazing', 'love', 'horrible', 'bad', 'terrible', 'awful', 'wow', 'hate']
In [ ]: