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
%time df2['Review_Processed'] = df2['Review_Processed'].map(lambda x: x.lower()) |
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
%time df2['Review_Processed'] = df2['Review_Processed'].map(lambda x : re.sub(r'[^\x00-\x7F]+',' ', x)) | |
%time df2['Review_Processed'] = df2['Review_Processed'].map(lambda x: re.sub(r'[^\w\s]', '', x)) |
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
from nltk.stem import WordNetLemmatizer | |
from nltk.corpus import stopwords | |
stop_words = stopwords.words('english') | |
%time df2['Review_Processed'] = df2['Review_Processed'].map(lambda x : ' '.join([w for w in x.split() if w not in stop_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
lemmer = WordNetLemmatizer() | |
%time df2['Review_Processed'] = df2['Review_Processed'].map(lambda x : ' '.join([lemmer.lemmatize(w) for w in x.split() if w not in stop_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
from sklearn.feature_extraction.text import CountVectorizer |
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
tf_vectorizer = CountVectorizer(min_df=.015, max_df=.8, max_features=no_features, ngram_range=[1, 3]) |
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
%time features = tf_vectorizer.fit_transform(df['user_review']) |
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
features_df = pd.DataFrame(features.toarray(), columns=tf_vectorizer.get_feature_names()) |
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
df = pd.concat([features_df,df['user_suggestion']],axis=1) |
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
df_tf_m_columns = df_tf_m.columns | |
df_tf_m_columns | |
res = [sub for sub in df_tf_m_columns if sub.isalpha()] | |
res.append('Flag_1') | |
df_tf_m = df_tf_m.drop(columns=[col for col in df_tf_m if col not in res]) | |
df_tf_m.head() |