<jupyter_start><jupyter_text>Analyze Product Sentiment<jupyter_code>import turicreate<jupyter_output><empty_output><jupyter_text>Read product review data<jupyter_code>products = turicreate.SFrame('./data/amazon_baby.sframe')<jupyter_output><empty_output><jupyter_text>Explore data<jupyter_code>products.head
products.groupby('name', 
                 operations={'count':turicreate.aggregate.COUNT()}
                ).sort('count',ascending=False)<jupyter_output><empty_output><jupyter_text>Examine the reviews for the most-reviewed product<jupyter_code>giraffe_reviews = products[products['name'] == '<NAME>']
giraffe_reviews.head(5)   ## let's look at the first 5 rows
giraffe_reviews.shape
giraffe_reviews['rating'].show()<jupyter_output><empty_output><jupyter_text>Building a sentiment classifier  Build word count vectors<jupyter_code>products['word_count'] = turicreate.text_analytics.count_words(products['review'])

products<jupyter_output><empty_output><jupyter_text>Define what is positive and negative sentiment<jupyter_code>products['rating'].show()
# ignore all 3*  reviews
products = products[products['rating'] != 3]
products.shape
# positive sentiment = 4-star or 5-star reviews
products['sentiment'] = products['rating'] >= 4
products
products['sentiment'].show()<jupyter_output><empty_output><jupyter_text>Train our sentiment classifier<jupyter_code>train_data, test_data = products.random_split(.8, seed=0)
sentiment_model = turicreate.logistic_classifier.create(train_data,target='sentiment', features=['word_count'], 
                                                        validation_set=test_data)<jupyter_output><empty_output><jupyter_text>Evaluate the sentiment model<jupyter_code>sentiment_model.evaluate(test_data)
roc_eval = sentiment_model.evaluate(test_data, metric='roc_curve')
roc_eval
turicreate.show(roc_eval['roc_curve']['fpr'],
                roc_eval['roc_curve']['tpr'],
                xlabel='False Positives',
                ylabel='True Positives',
                title='ROC')<jupyter_output><empty_output><jupyter_text>Apply the sentiment classifier to better understand the Giraffe reviews<jupyter_code>products['predicted_sentiment'] = sentiment_model.predict(products, output_type='probability')
products
giraffe_reviews = products[products['name']== '<NAME> G<NAME>']
giraffe_reviews<jupyter_output><empty_output><jupyter_text>Sort the Giraffe reviews according to predicted sentiment<jupyter_code>giraffe_reviews = giraffe_reviews.sort('predicted_sentiment', ascending=False)
giraffe_reviews
giraffe_reviews.tail(5)<jupyter_output><empty_output><jupyter_text>Show the most positive reviews<jupyter_code>giraffe_reviews[0]['review']
giraffe_reviews[1]['review']<jupyter_output><empty_output><jupyter_text>Most negative reviews<jupyter_code>giraffe_reviews[-1]['review']
giraffe_reviews[-2]['review']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12013888888888889, 'fraction_numerical': 0.004861111111111111, 'mean_word_length': 7.6, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '616560', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 960, 'n_tokens_neox': 922, 'n_words': 124, 'path': 'C01/w03/w03_notebook-classification.ipynb', 'repo_name': 'pascal-p/ML_UW_Spec', 'size': '2924'}