<jupyter_start><jupyter_text>When we used only the word embeddings, the R2 decreased from 0.70 (using bag of words model) to 0.56.Next, we try combining the BoW model with the word embeddings.<jupyter_code>X_train_BOW_embed = pd.DataFrame(X_train_desc)
X_train_BOW_embed["descriptions"] = description_train
X_test_BOW_embed = pd.DataFrame(X_test_desc)
X_test_BOW_embed["descriptions"] = description_test

X_train_BOW_embed.columns = [str(i) for i in X_train_BOW_embed.columns]
X_test_BOW_embed.columns = [str(i) for i in X_test_BOW_embed.columns]
text_pipeline = make_pipeline(CountVectorizer())

preprocess = make_column_transformer((text_pipeline, 'descriptions'),
                                     remainder = "passthrough")

pipe = make_pipeline(preprocess, Ridge(alpha=0.3))
pipe.fit(X_train_BOW_embed, y_train)
s1 = pipe.score(X_test_BOW_embed,y_test)

print("--------------------------------------------------------------------------------")
print("Results for regression using Word Embedding and Bag Of Words:")
print("--------------------------------------------------------------------------------")
print("Score on the test set is: " +str(s1))
text_pipeline = make_pipeline(CountVectorizer(ngram_range=(1, 3), min_df=4, stop_words="english", analyzer="char_wb"), Normalizer(),TfidfTransformer())

preprocess = make_column_transformer((text_pipeline, 'descriptions'),
                                     remainder = "passthrough")

pipe = make_pipeline(preprocess, Ridge(alpha=0.3))
pipe.fit(X_train_BOW_embed, y_train)
s1 = pipe.score(X_test_BOW_embed,y_test)

print("--------------------------------------------------------------------------------")
print("Results for regression using Word Embedding and Bag Of Words:")
print("--------------------------------------------------------------------------------")
print("Score on the test set is: " +str(s1))
preprocess = make_column_transformer((StandardScaler(), ['price']), 
                                     (TargetEncoder(), ['province','region_1','region_2','variety','winery']))
X_train_wo_desc = preprocess.fit_transform(X_train_wo_desc, y_train)
X_test_wo_desc = preprocess.transform(X_test_wo_desc)
X_train_w_desc = np.hstack((X_train_desc,X_train_wo_desc))
X_test_w_desc = np.hstack((X_test_desc,X_test_wo_desc))
r = Ridge().fit(X_train_w_desc, y_train)
s1 = r.score(X_test_w_desc, y_test)

print("--------------------------------------------------------------------------------")
print("Results for regression using Word Embedding with non-text features")
print("--------------------------------------------------------------------------------")
# print("The best parameters after grid search: " + str(grid.best_params_))
print("The score on test set is: " + str(s1))<jupyter_output>--------------------------------------------------------------------------------
Results for regression using Word Embedding with non-text features
--------------------------------------------------------------------------------
The score on test set is: 0.6734143946822839
{'fraction_non_alphanumeric': 0.3035596572181938, 'fraction_numerical': 0.012854317732366513, 'mean_word_length': 2.0441323971915746, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '153782', 'license': 'MIT', 'n_tokens_mistral': 856, 'n_tokens_neox': 841, 'n_words': 180, 'path': 'Predicting Wine-Quality from review texts and other properties/task2.ipynb', 'repo_name': 'Prasham8897/Applied_Machine_Learning', 'size': '3034'}