Emotional_model module

Emotional_model.clean_text(text)

It takes a string as input, and returns a string with all the non-alphanumeric characters removed, and all the words converted to lowercase

Parameters

text – The text to be cleaned

Returns

A string

Emotional_model.csv_update(csv_list, emotion_cat, train_data)

This function takes in a list of csv files, a list of emotion categories, and a training data set. It then uses the training data to train a classifier, and then uses the classifier to predict the emotion category of each row in the csv files. It then appends the emotion category to the csv files

Parameters
  • csv_list – a list of csv files to be updated

  • emotion_cat – a list of emotions

  • train_data – the training data

Returns

Nothing is being returned.

Emotional_model.generate_train_test(file_name)

It takes a file name as input, reads the file, and returns the train and test data

Parameters

file_name – The name of the file you want to read in.

Returns

train_X, test_X, train_y, test_y

Emotional_model.single_predict(clf_svm, test_str)

It takes a trained model and a string as input, and returns a prediction

Parameters
  • clf_svm – the trained model

  • test_str – a string of text to be classified

Returns

The prediction of the class of the test string.

Emotional_model.train_test(train_data)

It takes in a dataframe, splits it into train and test sets, vectorizes the text, trains a linear SVM, and returns the trained model

Parameters

train_data – the dataframe that contains the data to be trained on

Returns

The trained model

Emotional_model.train_vectorizer(train_X, test_X)

It takes in a list of strings (train_X) and a list of strings (test_X) and returns a list of vectors (train_X_vectors) and a list of vectors (test_X_vectors)

Parameters
  • train_X – the training data

  • test_X – The test data

Returns

The vectorizer is being returned.