Skip to content

Commit

Permalink
Modified demo, master_file, index,htnl
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-19 committed Apr 21, 2024
1 parent fab51cf commit 92834fb
Show file tree
Hide file tree
Showing 4 changed files with 620 additions and 2,009 deletions.
43 changes: 19 additions & 24 deletions Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -37,44 +37,42 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"#Importing Models:\n",
"from joblib import load\n",
"dt_clf = load(filename=\"Trained_models\\Decision_tree_tfid.joblib\")\n",
"rf_clf = load(filename=\"Trained_models\\Random_forest_tfid_100_trees.joblib\")\n",
"nb_clf = load(filename=\"Trained_models\\ComplimentNB_tfid.joblib\")\n",
"svm_clf = load(filename=\"Trained_models\\SVM_linear_kernel_tfid.joblib\")\n",
"perc_clf = load(filename=\"Trained_models\\Perceptron_tfid.joblib\")\n",
"lr_clf = load(filename=\"Trained_models\\Logistic_regression_tfid.joblib\")"
"dt_clf = load(filename=\"webapp/Trained_models/Decision_tree_tfid.joblib\")\n",
"rf_clf = load(filename=\"webapp/Trained_models/Random_forest_tfid_100_trees.joblib\")\n",
"nb_clf = load(filename=\"webapp/Trained_models/ComplimentNB_tfid.joblib\")\n",
"svm_clf = load(filename=\"webapp/Trained_models/SVM_linear_kernel_tfid.joblib\")\n",
"perc_clf = load(filename=\"webapp/Trained_models/Perceptron_tfid.joblib\")\n",
"lr_clf = load(filename=\"webapp/Trained_models/Logistic_regression_tfid.joblib\")\n",
"vectorizer = load(filename=\"webapp/Trained_models/Vectorizer.joblib\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from nltk.stem import PorterStemmer\n",
"import re\n",
"\n",
"def stem_text(txt_input):\n",
" # Initialize Porter Stemmer\n",
"\n",
" #Apply stemming to input text:\n",
" stemmer = PorterStemmer()\n",
" \n",
" txt_series = pd.Series(txt_input)\n",
" # Apply stemming to each word in the input text\n",
" stemmed_txt = txt_series.apply(lambda x: ' '.join([stemmer.stem(word) for word in x.split()]))\n",
" \n",
"\n",
" return stemmed_txt\n",
"\n",
"def preprocess_input(text, age, time_of_tweet):\n",
" # Remove special characters, numbers, and other punctuations\n",
"\n",
" processed_text = text.replace(\"[^a-zA-Z#]\", \" \")\n",
" \n",
" # Convert processed text to lowercase\n",
" processed_text = processed_text.lower()\n",
" \n",
" # Apply Porter stemming\n",
Expand All @@ -88,7 +86,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -129,31 +127,28 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"vectorizer = load(filename=\"Trained_models\\Vectorizer.joblib\")\n",
"\n",
"def predict_label(text, age, time_of_tweet):\n",
" # Preprocess input\n",
"\n",
" processed_data = preprocess_input(text, age, time_of_tweet)\n",
" \n",
" # Vectorize the processed text\n",
" vectorized_input = vectorizer.transform(processed_data['processed_text'])\n",
" \n",
" # Concatenate the age and time_of_tweet features with the vectorized text\n",
" X_input = sparse.hstack([processed_data[['age', 'time_of_tweet']], vectorized_input])\n",
"\n",
" # Make predictions using the AdaBoost classifier\n",
" \n",
" predictions = ensemble_predict(X_input, dt_clf, rf_clf, nb_clf, svm_clf, perc_clf, lr_clf)\n",
" \n",
" return predictions"
]
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down
Loading

0 comments on commit 92834fb

Please sign in to comment.