#!/usr/bin/python3 import pickle # import numpy as np # linear algebra # import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) # import pandas as pd # import numpy as np # import re # import nltk # from nltk.corpus import stopwords # from nltk.stem import WordNetLemmatizer # from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer, TfidfTransformer # from sklearn.decomposition import LatentDirichletAllocation # from sklearn.model_selection import train_test_split # from sklearn.naive_bayes import MultinomialNB # from sklearn.metrics import accuracy_score, confusion_matrix # from sklearn.linear_model import LogisticRegression # from sklearn.tree import DecisionTreeClassifier # from sklearn.ensemble import RandomForestClassifier # from sklearn.pipeline import Pipeline # from sklearn.model_selection import GridSearchCV # from sklearn.metrics import classification_report file_name = 'best_model.pkl' with open(file_name, 'rb') as file: model = pickle.load(file) # ohe = joblib.load('state_ohe.pkl') class_mapping = ['Music', 'Death', 'Environment', 'Affection'] class Profit: def __init__(self,data): self.data = data def predict(self): d_data = [data] predict = model.predict(d_data)[0] print(f"This prediction is: {class_mapping[predict-1]}\n") if __name__ == "__main__": print("************************") print("Poem prediction") print("************************\n\n") data = input('Enter Poem: ') obj = Profit(data) obj.predict()