Kaggle competition: Tweet Sentiment Extraction
<SOS> metric: Jaccard Kaggle data source: tweet-sentiment-extraction<choose_model_class>
import numpy as np
import pandas as pd
import os
ENet = make_pipeline(RobustScaler() , ElasticNet(alpha=0.0005, l1_ratio=.9, random_state=3))<choose_model_class>
list_csv =[]
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
if('.csv' in os.path.join(dirname, filename)) :
list_csv.append(os.path.join(dirname, filename))
list_csv = list(set(list_csv)- set(['/kaggle/input/tweet-sentiment-extraction/train.csv',
'/kaggle/input/tweet-sentiment-extraction/test.csv',
'/kaggle/input/tweet-sentiment-extraction/sample_submission.csv']))
KRR = KernelRidge(alpha=0.6, kernel='polynomial', degree=2, coef0=2.5 )<choose_model_class>
df_test = pd.read_csv("/kaggle/input/tweet-sentiment-extraction/test.csv")
 list_df =[]
for i in list_csv:
df = pd.read_csv(i)
 df_test = pd.merge(df_test, df, on = 'textID' )
GBoost = GradientBoostingRegressor(n_estimators=3000, learning_rate=0.05,
max_depth=4, max_features='sqrt',
min_samples_leaf=15, min_samples_split=10,
loss='huber', random_state =5 )<choose_model_class>
df_sentiment = df_test.copy()
df_sentiment.columns = ['textID', 'text', 'sentiment'] + list('selected_text_' + pd.Series(range(len(list_csv)) ).astype('str'))
model_xgb = xgb.XGBRegressor(colsample_bytree=0.4603, gamma=0.0468,
learning_rate=0.05, max_depth=3,
min_child_weight=1.7817, n_estimators=2200,
reg_alpha=0.4640, reg_lambda=0.8571,
subsample=0.5213, silent=1,
random_state =7, nthread = -1)
<choose_model_class>
count = 0
dictionary = {}
for row in df_sentiment.iterrows() :
list_elements = [str(i ).lower().strip() for i in row[1].to_list() [3:]]
cleaned_text = ' '.join(list_elements)
 cleaned_text = cleaned_text.split(' ')
 df_idf = pd.Series(cleaned_text ).value_counts() /(len(list_csv)-1)
 dictionary[row[1].textID] = ' '.join(df_idf[df_idf >.7].index)
 count = count+1
model_lgb = lgb.LGBMRegressor(objective='regression',num_leaves=5,
learning_rate=0.05, n_estimators=720,
max_bin = 55, bagging_fraction = 0.8,
bagging_freq = 5, feature_fraction = 0.2319,
feature_fraction_seed=9, bagging_seed=9,
min_data_in_leaf =6, min_sum_hessian_in_leaf = 11 )<compute_test_metric>
df = pd.DataFrame.from_dict(dictionary, columns=['selected_text'], orient = 'index' ).reset_index()
df.columns = ['textID', 'selected_text']
df.head()
score = rmsle_cv(lasso)
 print("
Lasso score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))<compute_test_metric>
df_sample = pd.read_csv("/kaggle/input/tweet-sentiment-extraction/sample_submission.csv" )
score = rmsle_cv(ENet)
 print("ElasticNet score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))<compute_test_metric>
df_submission = pd.merge(df_sample,df, on = 'textID', how = 'left' )
score = rmsle_cv(KRR)
 print("Kernel Ridge score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))<compute_test_metric>
df_submission = df_submission.fillna('')
 df_submission['selected_text']= df_submission.selected_text_x + df_submission.selected_text_y
df_submission.head()
<compute_test_metric><EOS> 
df_submission[['textID', 'selected_text']].to_csv("submission.csv", index = False )