text_plain_output_1.png
from wordcloud import WordCloud

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

import sklearn

df = pd.read_csv('../input/sentiment-analysis-for-financial-news/all-data.csv', encoding='ISO-8859-1')

df = df.rename(columns={'neutral': 'sentiment', 'According to Gran , the company has no plans to move all production to Russia , although that is where the company is growing .': 'statement'})

df.shape

df.drop_duplicates(subset=['statement'], keep='first', inplace=True)

text = ' '.join([x for x in df.statement])
wordcloud = WordCloud(background_color='white').generate(text)
plt.axis('off')

text = ' '.join([x for x in df.statement[df.sentiment == 'neutral']])
wordcloud = WordCloud(background_color='white').generate(text)
plt.axis('off')

text = ' '.join([x for x in df.statement[df.sentiment == 'positive']])
wordcloud = WordCloud(background_color='white').generate(text)
plt.axis('off')

text = ' '.join([x for x in df.statement[df.sentiment == 'negative']])
wordcloud = WordCloud(background_color='white').generate(text)
plt.axis('off')

def making_label(st):
    if st == 'positive':
        return 0
    elif st == 'neutral':
        return 2
    else:
        return 1
train['label'] = train['sentiment'].apply(making_label)
eva['label'] = eva['sentiment'].apply(making_label)

train_df = pd.DataFrame({'text': train['statement'][:1500].replace('\\n', ' ', regex=True), 'label': train['label'][:1500]})
eval_df = pd.DataFrame({'text': eva['statement'][-400:].replace('\\n', ' ', regex=True), 'label': eva['label'][-400:]})

lst = []
for arr in model_outputs:
    lst.append(np.argmax(arr))

true = eval_df['label'].tolist()
predicted = lst

import sklearn
mat = sklearn.metrics.confusion_matrix(true, predicted)
mat

df_cm = pd.DataFrame(mat, range(3), range(3))
sns.heatmap(df_cm, annot=True)
plt.show()