- Imanol Armando González Solís
- Marco Antonio Lució Sosa
- Pedro Gabriel Sanchez Valdez
- José Miguel Guerrero Jiménez
This program was build using Pandas, TextBlob and Profanity_Checker libraries to perform sentiment analysis and detect inappropriate comments in a set of customer reviews for VivaAerobus. The goal was to delete inappropriate or abusive comments, determine overall customer satisfaction and obtain the main complaints of customers in order to improve in these areas. This project was done in a 24-hour data science marathon on May 6-7th , 2023 and for confidentiality reasons the code was modified to work with sample databases created by us.
This code performs the following tasks:
- Imports the necessary libraries:
pandas,TextBlob, andProfanity. - Defines the necessary variables, such as the database file path, sheet name, rate column, and column to analyze.
- Defines a function called
cleanDatato clean the data. - Reads the Excel file using
pd.read_excel. - Separates the comments into three groups based on the rating.
- Drops unnecessary columns from each group, keeping only the column to analyze.
- Calls the
cleanDatafunction on each group to clean the comments. - Writes the cleaned data into different sheets in a new Excel file called 'cleanDatabase.xlsx'.
This code performs the following tasks:
- Import the libraries pandas, numpy, sklearn, and textblob.
- Declare the path of the file
dataToExtractTopic.xlsx. - Set the constants
n_features,n_top_words, andn_components. - Define the testing documents as a list of sentences.
- Define the topics as a list of category names.
- Initialize the TfidfVectorizer with specified parameters and transform the testing documents.
- Fit the NMF model to the TF-IDF matrix.
- Define a function
get_relevant_topicto get the most relevant topic for a given text. - Read the database file
dataToExtractTopic.xlsxinto a DataFrame. - Iterate over each text in the database and determine the relevant topic using the
get_relevant_topicfunction. - Create a new DataFrame with columns "Columns" and "Topic" to store the text and its corresponding topic.
- Save the DataFrame to an Excel file named "topicCategorization.xlsx".
The code performs sentiment analysis on a dataset using the TextBlob library, Naive Bayes classifier, and MaxEnt classifier. Here's a breakdown of the steps:
- Import the necessary libraries:
TextBlob,NaiveBayesClassifier,MaxEntClassifier, andpandas. - Define the training data for the sentiment analysis model.
- Declare the path to the database file.
- Create the Naive Bayes classifier using the training data.
- Create the MaxEnt classifier using the training data.
- Prepare lists to store sentences, responses, probabilities, and intensities.
- Read the database file into a pandas dataframe.
- Iterate over the sentences in the database.
- Append each sentence to the list of sentences to check.
- Classify the text using the Naive Bayes classifier from TextBlob.
- Append the classified sentiment to the list of responses.
- Calculate the probability of the sentiment using the MaxEnt classifier.
- Append the probability to the list of probabilities.
- Print the sentiment classification and probability for each sentence.
- Create a pandas dataframe with the results.
- Write the dataframe to an Excel file named "subjectivityAnalysis.xlsx".