Python Forum
ML - Empty Results - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: ML - Empty Results (/thread-26903.html)



ML - Empty Results - BadWhite - May-18-2020

Hey Guys,

I'm newbie to the ML world and I'm confronting an annoying problem which is when I run the code, nothing happens, just an empty screen. The code is below:


import pandas as pd
import numpy as np
import gensim
import spacy
import nltk
import text_normalizer as tn
from afinn import Afinn

np.set_printoptions(precision=2, linewidth=80)

dataset = pd.read_csv(r'movie_reviews.csv')
reviews = np.array(dataset['review'])
sentiments = np.array(dataset['sentiment'])
# extract data for model evaluation
test_reviews = reviews[35000:]
test_sentiments = sentiments[35000:]
sample_review_ids = [7626, 3533, 13010]
# normalize dataset
norm_test_reviews = tn.normalize_corpus(test_reviews)

afn = Afinn(emoticons=True)

for review, sentiment in zip(test_reviews[sample_review_ids], test_sentiments[sample_review_ids]):
    print('REVIEW:', review)
    print('Actual Sentiment:', sentiment)
    print('Predicted Sentiment polarity:', afn.score(review))
    print('-'*60)


And I'm using PyCharm, Any Ideas?


RE: ML - Empty Results - BadWhite - May-19-2020

The code works fine, that problem was with the time consuming to give the results, around 15 mins which is really big time.

Any idea to make the run process faster?



RE: ML - Empty Results - scidam - May-19-2020

The code uses third-party machine learning libraries, so it is likely nothing
to improve with those. However, I suspect that the bottleneck is for-loop (line No. 23);
I don't know exactly, but you can try to pass to afn.score the entire array test_reviews[sample_review_ids]. If afn.score is implemented, e.g. in C, the computations will
be slightly faster.