text_plain_output_1.png
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer

from sklearn.metrics import accuracy_score, confusion_matrix, classification_report

from sklearn.model_selection import train_test_split

from sklearn.pipeline import Pipeline

from sklearn.svm import LinearSVC

from wordcloud import WordCloud

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

data = pd.read_csv('../input/sentiment-analysis-for-financial-news/all-data.csv', names=['Sentiment', 'Tweet'], encoding='latin-1')

temp = data.groupby('Sentiment').count()['Tweet'].reset_index().sort_values(by='Tweet', ascending=False)
temp.style.background_gradient(cmap='Purples')

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

data = data.drop(['list_mots'], axis=1)

x_train, x_test, y_train, y_test = train_test_split(data.Tweet_freq, data.Sentiment_encoded, test_size=0.3, random_state=0)

pipe_svm = Pipeline([('tfidf', TfidfVectorizer()), ('model', LinearSVC())])
model_svm = pipe_svm.fit(x_train, y_train)
prediction_svm = model_svm.predict(x_test)

print('Matrice de confusion en forme de heatmap')
cm_svm = confusion_matrix(y_test, prediction_svm)
noms_des_classes = data.Sentiment.unique()
plt.figure(figsize=(10, 7))
ax = sns.heatmap(cm_svm, annot=True, linewidths=1, fmt='d', xticklabels=noms_des_classes, yticklabels=noms_des_classes)
plt.setp(ax.get_xticklabels(), rotation=45, ha='right', rotation_mode='anchor')
plt.show()
print('Rapport de classification')
print(classification_report(y_test, prediction_svm, target_names=noms_des_classes))