Code Monkey home page Code Monkey logo

sentiment-analysis's Introduction

Sentiment-Analysis

Sentiment Analysis using the "Sentiment Labelled Sentences" dataset from UCI, focusing on the Amazon dataset.

Contact

Sentiment Analysis on Amazon Cells Dataset

Project Overview

This repository contains code for performing Sentiment Analysis using the "Sentiment Labelled Sentences" dataset from UCI. The primary focus is on analyzing the Amazon dataset. Sentiment Analysis is a type of classification that categorizes text data into positive or negative sentiments.

The project follows these main steps:

  1. Preprocessing: The dataset is cleaned, including removing punctuation, converting text to lowercase, removing extra white spaces, and eliminating stopwords. Additionally, stemming and lemmatization are applied to the text data.
  2. Classification: The preprocessed data is split into training and testing sets. Text data is transformed into numerical feature vectors using TF-IDF (Term Frequency-Inverse Document Frequency) vectorization. Two classification models, Multinomial Naive Bayes, and Logistic Regression, are trained on the TF-IDF transformed data and used for sentiment prediction.
  3. Evaluation & Comparison: The models' performance is evaluated and compared using metrics such as confusion matrices, F1-Score, accuracy, and error rate.

Preprocessing

  • Loading Packages: Required libraries and packages are imported, including NLTK for natural language processing.
  • Loading and Preparing Dataset: The Amazon dataset is loaded into a Pandas data frame, and columns are named as 'Sentence' and 'Class'. A temporary data frame ('temp') is created for storing preprocessed values.
  • Data Cleaning: Punctuation is removed from sentences, letters are converted to lowercase, and extra white spaces are removed.
  • Stopword Removal: NLTK's stopwords are removed from the sentences.
  • Stemming: Words are stemmed using Porter Stemmer.
  • Lemmatization: Words are lemmatized using WordNetLemmatizer.

Classification

  • Data Splitting: The preprocessed sentences and class labels are split into training and testing sets.
  • Text Vectorization (TF-IDF): TF-IDF vectorization is applied to convert text data into numerical feature vectors.

Multinomial Naive Bayes

  • A Multinomial Naive Bayes model is created and trained on the TF-IDF transformed training data.
  • Predictions are made on the testing data.

Logistic Regression

  • A Logistic Regression model is created and trained on the TF-IDF transformed training data.
  • Predictions are made on the testing data.

Evaluation & Comparison

  • For both Naive Bayes and Logistic Regression models, the following metrics are printed and compared:
    • Confusion matrix
    • F1-Score
    • Accuracy
    • Error rate

This code demonstrates the entire process of sentiment analysis, from data preprocessing to model evaluation and comparison using two different classification algorithms.

Feel free to explore the code and modify it for your own sentiment analysis tasks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.