<jupyter_start><jupyter_text>Read sompe product data<jupyter_code>products = graphlab.SFrame('amazon_baby.gl/')<jupyter_output>This non-commercial license of GraphLab Create is assigned to <EMAIL> and will expire on July 05, 2017. For commercial licensing options, visit https://turi.com/buy/.<jupyter_text>Lets Explore<jupyter_code>products.head()<jupyter_output><empty_output><jupyter_text>Build Word Count Vector<jupyter_code>products['word_count'] = graphlab.text_analytics.count_words(products['review'])
products.head()
graphlab.canvas.set_target('ipynb')
products['name'].show()<jupyter_output><empty_output><jupyter_text>Explore Vulli Sophie<jupyter_code>giraff_review = products[products['name'] == '<NAME> the Giraffe Teether']
print len(giraff_review)
giraff_review['rating'].show(view = 'Categorical')<jupyter_output><empty_output><jupyter_text>Build a sentiment Classifier<jupyter_code>products = products[products['rating'] != 3]
products['sentiment'] = products['rating']>=4
products.tail()<jupyter_output><empty_output><jupyter_text>Lets train the sentiment classifier<jupyter_code>train_data, test_data = products.random_split(.8, seed=0)
sentiment_model = graphlab.logistic_classifier.create(train_data, 
                                                      target='sentiment', 
                                                      features=['word_count'],
                                                      validation_set = test_data)<jupyter_output><empty_output><jupyter_text>Evaluate The model<jupyter_code>sentiment_model.evaluate(test_data, metric = 'roc_curve')
sentiment_model.show(view='Evaluation')<jupyter_output><empty_output><jupyter_text>Apply Learned model to understand the sentiment<jupyter_code>giraff_review['predicted_sentiment'] = sentiment_model.predict(giraff_review, output_type='probability')
giraff_review.head()<jupyter_output><empty_output><jupyter_text>Sort the reviews<jupyter_code>giraff_review = giraff_review.sort('predicted_sentiment', ascending=False)
giraff_review.head()
giraff_review[0]['review']
giraff_review[1]['review']
giraff_review[-1]['review']
giraff_review[-2]['review']
selected_words = ['awesome', 'great', 'fantastic', 'amazing', 'love', 'horrible', 'bad', 'terrible', 'awful', 'wow', 'hate']
type(products['word_count'][0])
def select_word_count(word_count, word):
    if word in word_count:
        return word_count[word]
    return 0
print select_word_count(products['word_count'][1], 'awesome')
for word in selected_words:
    products[word] = products['word_count'].apply(lambda x: select_word_count(x, word))
products.sort('awesome', ascending=False).head()
words = dict()
for i in products['word_count']:
    for k,v in i.iteritems():
        if k in words:
            value = words[k]
            words[k] = value + v
        else:
            words[k] = v
for w in selected_words:
    print w, '=', words[w]
train_data_one, test_data_one = products.random_split(.8, seed=0)
selected_words_model = graphlab.logistic_classifier.create(train_data_one,
                                                           'selected_words_model', 
                                                           features=selected_words)<jupyter_output>PROGRESS: Creating a validation set from 5 percent of training data. This may take a while.
          You can set ``validation_set=None`` to disable validation tracking.
{'fraction_non_alphanumeric': 0.12023633677991137, 'fraction_numerical': 0.005908419497784343, 'mean_word_length': 4.39171974522293, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 38, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '561137', 'license': 'Apache-2.0', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1037, 'n_words': 188, 'path': 'Machine-Learning-Specialization/case_study_approach/week3/Analyzing_Product_Sentiment.ipynb', 'repo_name': 'subhankarb/Machine-Learning-PlayGround', 'size': '3405'}