This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Prediction from test dataset | |
from sklearn.metrics import classification_report, confusion_matrix, f1_score, precision_score, recall_score | |
model_name=[] | |
precision_array=[] | |
recall_array=[] | |
f1_array=[] | |
test_time=[] | |
print("Classifiation Report\n") | |
print("*****************************************************") | |
for i, pipeline in enumerate(pipelines): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Creating a list of Pipeline with well-known ML models | |
from sklearn.pipeline import make_pipeline | |
from sklearn.naive_bayes import MultinomialNB,ComplementNB | |
from sklearn.linear_model import LogisticRegression, RidgeClassifier | |
from sklearn.svm import SVC | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer | |
from sklearn.tree import DecisionTreeClassifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
freq_words=df.Treated_Tweet.str.split(expand=True).stack().value_counts()[:10] | |
freq_words=list(freq_words.index) | |
rare_words=df.Treated_Tweet.str.split(expand=True).stack().value_counts() | |
rare_words=list(rare_words.loc[lambda x: x==1].index) | |
#Remove Frequent and Rare words | |
def remove_noise_words(text): | |
edited_text=text.split() | |
edited_text=[word for word in edited_text if word not in freq_words] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
import string | |
import re | |
from nltk.stem.snowball import SnowballStemmer | |
stopwords=nltk.corpus.stopwords.words('english') | |
snowball_stemmer=SnowballStemmer(language='english') | |
def treat_text(text): | |
edited_text=re.sub('\W'," ",text) #replace any sumbol with whitespace |