{ "cells": [ { "cell_type": "markdown", "id": "56cccab6", "metadata": {}, "source": [ "# Emotions Detection in Text" ] }, { "cell_type": "code", "execution_count": 1, "id": "f0814628-3d83-4fd6-a511-2eccf79f9f1e", "metadata": {}, "outputs": [], "source": [ "# EDA\n", "import pandas as pd\n", "import numpy as np\n", "\n", "# Load Data Viz Pkgs\n", "import seaborn as sns\n", "\n", "# Load Text Cleaning Pkgs\n", "import neattext.functions as nfx\n", "\n", "# Load ML Pkgs\n", "# Estimators\n", "from sklearn.linear_model import LogisticRegression\n", "from sklearn.naive_bayes import MultinomialNB\n", "\n", "# Transformers\n", "from sklearn.feature_extraction.text import CountVectorizer\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.metrics import accuracy_score,classification_report,confusion_matrix" ] }, { "cell_type": "code", "execution_count": 2, "id": "b209e004-ab77-4407-8689-b4318944d47f", "metadata": {}, "outputs": [], "source": [ "# Load Dataset\n", "df = pd.read_csv(\"../data/emotion_dataset_raw.csv\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "fea2d4c0-3bdd-405e-ab69-507ceaac36cb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Emotion | \n", "Text | \n", "
---|---|---|
0 | \n", "neutral | \n", "Why ? | \n", "
1 | \n", "joy | \n", "Sage Act upgrade on my to do list for tommorow. | \n", "
2 | \n", "sadness | \n", "ON THE WAY TO MY HOMEGIRL BABY FUNERAL!!! MAN ... | \n", "
3 | \n", "joy | \n", "Such an eye ! The true hazel eye-and so brill... | \n", "
4 | \n", "joy | \n", "@Iluvmiasantos ugh babe.. hugggzzz for u .! b... | \n", "
\n", " | Emotion | \n", "Text | \n", "Clean_Text | \n", "
---|---|---|---|
0 | \n", "neutral | \n", "Why ? | \n", "? | \n", "
1 | \n", "joy | \n", "Sage Act upgrade on my to do list for tommorow. | \n", "Sage Act upgrade list tommorow. | \n", "
2 | \n", "sadness | \n", "ON THE WAY TO MY HOMEGIRL BABY FUNERAL!!! MAN ... | \n", "WAY HOMEGIRL BABY FUNERAL!!! MAN HATE FUNERALS... | \n", "
3 | \n", "joy | \n", "Such an eye ! The true hazel eye-and so brill... | \n", "eye ! true hazel eye-and brilliant ! Regular f... | \n", "
4 | \n", "joy | \n", "@Iluvmiasantos ugh babe.. hugggzzz for u .! b... | \n", "ugh babe.. hugggzzz u .! babe naamazed nga ako... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
34787 | \n", "surprise | \n", "@MichelGW have you gift! Hope you like it! It'... | \n", "gift! Hope like it! hand wear ! It'll warm! Lol | \n", "
34788 | \n", "joy | \n", "The world didnt give it to me..so the world MO... | \n", "world didnt me..so world DEFINITELY cnt away!!! | \n", "
34789 | \n", "anger | \n", "A man robbed me today . | \n", "man robbed today . | \n", "
34790 | \n", "fear | \n", "Youu call it JEALOUSY, I call it of #Losing YO... | \n", "Youu JEALOUSY, #Losing YOU... | \n", "
34791 | \n", "sadness | \n", "I think about you baby, and I dream about you ... | \n", "think baby, dream time | \n", "
34792 rows × 3 columns
\n", "Pipeline(steps=[('cv', CountVectorizer()), ('lr', LogisticRegression())])In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Pipeline(steps=[('cv', CountVectorizer()), ('lr', LogisticRegression())])
CountVectorizer()
LogisticRegression()
Pipeline(steps=[('cv', CountVectorizer()), ('lr', LogisticRegression())])In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Pipeline(steps=[('cv', CountVectorizer()), ('lr', LogisticRegression())])
CountVectorizer()
LogisticRegression()