<jupyter_start><jupyter_text>Analyze Product Sentiment<jupyter_code>import turicreate as tc<jupyter_output><empty_output><jupyter_text>Read product review data<jupyter_code>products = tc.SFrame('amazon_baby.sframe')<jupyter_output><empty_output><jupyter_text>Explore data<jupyter_code>products.head(5)
products.groupby('name',operations={'count':tc.aggregate.COUNT()}).sort('count',ascending=False).head(5)<jupyter_output><empty_output><jupyter_text>Examine the reivews for the most-reviewed product<jupyter_code>giraffe_reviews = products[products['name']=='<NAME> G<NAME>']
giraffe_reviews.head(5)
len(giraffe_reviews)
giraffe_reviews['rating'].show()<jupyter_output><empty_output><jupyter_text>Building a sentiment classifier  Build word count vectors<jupyter_code>products['word_count'] = tc.text_analytics.count_words(products['review'])
products.head(5)<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]
#positive sentiment = 4-star or 5-star reviews
products['sentiment'] = products['rating'] >= 4
products.head(5)
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 = tc.logistic_classifier.create(train_data,target='sentiment',
                                                features=['word_count'], validation_set=test_data)<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.head(5)
sentiment_model.evaluate(test_data)
giraffe_reviews = products[products['name']== '<NAME> Giraffe Teether']
giraffe_reviews.head()<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.head(5)
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 reivews<jupyter_code>giraffe_reviews[-1]['review']
giraffe_reviews[-2]['review']<jupyter_output><empty_output><jupyter_text>Quiz<jupyter_code>diaper_champ_reviews = products[products['name'] == 'Baby Trend Diaper Champ']
diaper_champ_reviews['predicted_sentiment'][0]
diaper_champ_reviews['review'][0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12860892388451445, 'fraction_numerical': 0.007874015748031496, 'mean_word_length': 11.826923076923077, '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': '247044', 'license': 'MIT', 'n_tokens_mistral': 931, 'n_tokens_neox': 913, 'n_words': 111, 'path': '01_machine_learning_foundations/week_3/classification.ipynb', 'repo_name': 'juanhenao21/machine_learning', 'size': '2695'}