Kaggle competition: Sentiment Analysis on Movie Reviews
clf.fit(train_ , label)
 pre = clf.predict(test_)
 submit = pd.read_csv('.. /input/sample_submission.csv')
 submit.head()
submit.SalePrice = pre
submit.to_csv('submit.csv', index = False )<set_options>
train = pd.read_csv(".. /input/train.tsv", sep='\t')
 test = pd.read_csv(".. /input/test.tsv", sep='\t')
 train['Sentiment'] = train['Sentiment'].apply(str)
%matplotlib inline<load_from_csv>
train.Sentiment.value_counts()
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv')
 train_df.head()<count_missing_values>
!pip install pytorch-pretrained-bert pytorch-nlp
train_df.isnull().sum() , print('------'),test_df.isnull().sum()<categorify>
% matplotlib inline
sex_map = {'male' : 0, 'female' : 1}
train_df['Sex'] = train_df['Sex'].replace(sex_map)
 fare_map = {'Unknown' : 0,'1-20' : 1,'21-41' : 2,'42-60' :3 ,'61-81' : 4,'82-100' : 5,'101+' : 6}
train_df['FareGroup'] = train_df['FareGroup'].replace(fare_map )<categorify>
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 n_gpu = torch.cuda.device_count()
torch.cuda.get_device_name(0 )
def age_imputer(dataf_to_impute,dataf_to_ref):
title_age = dataf_to_ref[['Title','Age']][dataf_to_ref['Age'].notnull() ].groupby('Title' ).mean()
for Id in dataf_to_impute['PassengerId'][dataf_to_impute['Age'].isnull() ]:
for tle in dataf_to_impute['Title'][dataf_to_impute['PassengerId'] == Id]:
dataf_to_impute['Age'][dataf_to_impute['PassengerId'] == Id] = title_age.loc[tle].sum()
def title_maker(dataframe):
dataframe['Title'] =(dataframe['Name'][dataframe['Name'].notnull() ] ).apply(lambda x: list(list(x.split(',')) [1].split(' ')) [1] )<count_missing_values>
train['Sentiment'] = train.Sentiment.astype(int)
 test['Sentiment'] = test.Sentiment.astype(int )
train_df['Age'].isna().sum()<categorify>
sentences = train.Phrase.values
sentences = ["[CLS] " + sentence + " [SEP]" for sentence in sentences]
labels = train.Sentiment.values
age_map = {'Unknown' : 0,
'Baby' : 1,
'Child' : 2,
'Student' : 3,
'Teenager' : 4,
'Young Adult' : 5,
'Adult' : 6,
'Senior' : 7}
train_df['AgeGroup'] = train_df['AgeGroup'].replace(age_map )<prepare_x_and_y>
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
 tokenized_texts = [tokenizer.tokenize(sent)for sent in sentences]
print("Tokenize the first sentence:")
 print(tokenized_texts[0] )
Y = train_df['Survived'].values.ravel()
X_new = train_df[['Pclass','FareGroup','AgeGroup','SibSpBool','ParchBool','Sex','CabinBool']]
X_orig = train_df[['Pclass','Sex','Age','SibSp','Parch','Fare','CabinBool']]<compute_train_metric>
import seaborn as sns
model_RF = RandomForestClassifier(random_state=0)
 my_pipeline = make_pipeline(model_RF)
 scores1_RF = cross_val_score(my_pipeline,X_orig,Y,scoring = 'accuracy',cv=5)
 scores2_RF = cross_val_score(my_pipeline,X_new,Y,scoring = 'accuracy', cv=5)
 Y_preds1 = cross_val_predict(my_pipeline,X_orig,Y)
 print('Score for model with original features : {}'.format(scores1_RF*100))
print('Score for model with simplified features : {}'.format(scores2_RF*100))<compute_train_metric>
MAX_LEN = 32
model = XGBClassifier(random_state=0)
 my_pipeline = make_pipeline(model)
 scores1_XG = cross_val_score(my_pipeline,X_orig,Y,scoring = 'accuracy',cv=5)
 scores2_XG = cross_val_score(my_pipeline,X_new,Y,scoring = 'accuracy', cv=5)
 Y_preds1 = cross_val_predict(my_pipeline,X_orig,Y)
 print('Score for model with original features : {}'.format(scores1_XG*100))
print('Score for model with simplified features : {}'.format(scores2_XG*100))<compute_train_metric>
input_ids = pad_sequences([tokenizer.convert_tokens_to_ids(txt)for txt in tokenized_texts],
maxlen=MAX_LEN, dtype="long", truncating="post", padding="post" )
model = SVC(random_state=0, gamma="auto")
 my_pipeline = make_pipeline(model)
 scores1_SV = cross_val_score(my_pipeline,X_orig,Y,scoring = 'accuracy',cv=5)
 scores2_SV = cross_val_score(my_pipeline,X_new,Y,scoring = 'accuracy', cv=5)
 Y_preds1 = cross_val_predict(my_pipeline,X_orig,Y)
 print('Score for model with original features : {}'.format(scores1_SV*100))
print('Score for model with simplified features : {}'.format(scores2_SV*100))<count_missing_values>
input_ids = [tokenizer.convert_tokens_to_ids(x)for x in tokenized_texts]
test_df1 = test_df
test_df1['Age'].isna().sum()<categorify>
input_ids = pad_sequences(input_ids, maxlen=MAX_LEN, dtype="long", truncating="post", padding="post" )
bins = [-1,0 ,5 ,12 , 18, 24, 35, 60, np.inf]
labels = ['Unknown','Baby','Child','Student','Teenager','Young Adult','Adult','Senior']
test_df1['AgeGroup'] = pd.cut(test_df1['Age'],bins,labels = labels)
 age_map = {'Unknown' : 0,
'Baby' : 1,
'Child' : 2,
'Student' : 3,
'Teenager' : 4,
'Young Adult' : 5,
'Adult' : 6,
'Senior' : 7}
test_df1['AgeGroup'] = test_df1['AgeGroup'].replace(age_map)
 sex_map = {'male' : 0, 'female' : 1}
test_df1['Sex'] = test_df1['Sex'].replace(sex_map)
 test_df1['CabinBool'] =(test_df1['Cabin'].notnull().astype('int'))
test_df1['Fare'] = test_df1['Fare'].fillna(-0.5)
 bins = [-1, 0, 20 ,41 , 60, 81, 100, np.inf]
labels = ['Unknown','1-20','21-41','42-60','61-81','82-100','101+']
test_df1['FareGroup'] = pd.cut(test_df1['Fare'],bins,labels = labels)
 fare_map = {'Unknown' : 0,'1-20' : 1,'21-41' : 2,'42-60' :3 ,'61-81' : 4,'82-100' : 5,'101+' : 6}
test_df1['FareGroup'] = test_df1['FareGroup'].replace(fare_map)
 test_df1['ParchBool'] =(test_df1['Parch'].apply(lambda x: 1 if x>0 else 0))
test_df1['SibSpBool'] =(test_df1['SibSp'].apply(lambda x: 1 if x>0 else 0))<save_to_csv>
attention_masks = []
for seq in input_ids:
seq_mask = [float(i>0)for i in seq]
attention_masks.append(seq_mask )
ids = test_df1['PassengerId']
model = SVC(random_state=0, gamma="auto")
 model.fit(X_new,Y)
 test_df1_pred = test_df1[X_new.columns]
predictions = model.predict(test_df1_pred)
 output = pd.DataFrame({'PassengerId' : ids,
'Survived' : predictions})
 output.to_csv('submission.csv', index=False )<feature_engineering>
train_inputs, validation_inputs, train_labels, validation_labels = train_test_split(input_ids, labels,
random_state=2018, test_size=0.1)
 train_masks, validation_masks, _, _ = train_test_split(attention_masks, input_ids,
random_state=2018, test_size=0.1 )
def feature_engg_train(df):
df['Title'] = df['Name'].map(lambda name:name.split('.')[0].split(',')[1].strip())
 titles_dict_train = {}
for title in ['Capt','Col','Major']:
titles_dict_train[title] = 'Officer'
for title in ['Rev','Dr']:
titles_dict_train[title] = 'Other'
for title in ['Don','the Countess','Jonkheer','Lady','Sir']:
titles_dict_train[title] = 'Royalty'
for title in ['Ms','Miss','Mlle']:
titles_dict_train[title] = 'Miss'
for title in ['Mrs','Mme']:
titles_dict_train[title] = 'Mrs'
titles_dict_train['Mr'] = 'Mr'
titles_dict_train['Master'] = 'Master'
df['Title'] = df['Title'].map(titles_dict_train)
 title_dummies = pd.get_dummies(df['Title'],prefix='Title')
 df = pd.concat([df,title_dummies],axis=1)
 grouped_sex_class = df.groupby(['Sex','Pclass','Title'])
 def impute_median(series):
return(series.fillna(series.median()))
df['Age'] = grouped_sex_class['Age'].transform(impute_median)
 df['Fare'].fillna(df['Fare'].mean() ,inplace=True)
 df['Embarked'].fillna('S',inplace=True)
 embarked_dummies = pd.get_dummies(df['Embarked'],prefix='Embarked')
 df = pd.concat([df,embarked_dummies],axis=1)
 df['Cabin'].fillna('X',inplace=True)
 df['Cabin_clean'] = df['Cabin'].apply(lambda x: x[0])
 cabin_dummies = pd.get_dummies(df['Cabin_clean'],prefix='Cabin')
 df = pd.concat([df,cabin_dummies],axis=1)
 sex_dict = dict(zip(df['Sex'].unique() ,range(0,2)))
 df['Sex'] = df['Sex'].map(sex_dict)
 pclass_dummies = pd.get_dummies(df['Pclass'],prefix='Pclass')
 df = pd.concat([df,pclass_dummies],axis=1)
 df['Family'] = df['SibSp'] + df['Parch'] + 1
df['Family_single'] = df['Family'].map(lambda x: 1 if x==1 else 0)
 df['Family_small'] = df['Family'].map(lambda x: 1 if 2<=x<=4 else 0)
 df['Family_large'] = df['Family'].map(lambda x: 1 if x>=4 else 0)
 df.drop(['Name','Pclass','Ticket','Cabin','Cabin_clean',\
'Embarked','Title'],axis=1,inplace=True)
 return(df)
 def feature_engg_test(df):
df['Title'] = df['Name'].map(lambda name:name.split('.')[0].split(',')[1].strip())
 titles_dict_test = { 'Col': 'Officer',
'Dona': 'Royalty','Dr': 'Other', 'Master': 'Master', 'Miss': 'Miss',\
'Mr': 'Mr', 'Mrs': 'Mrs', 'Ms': 'Miss', 'Rev': 'Other'}
df['Title'] = df['Title'].map(titles_dict_test)
 test_dummies_title = pd.get_dummies(df['Title'],prefix='Title')
 df = pd.concat([df,test_dummies_title],axis=1)
 df['Fare'].fillna(df['Fare'].mean() ,inplace=True)
 grouped_sex_class_test = df.groupby(['Sex','Pclass','Title'])
 def impute_median(series):
return series.fillna(series.median())
 df['Age'] = grouped_sex_class_test['Age'].transform(impute_median)
 df['Embarked'].fillna('S',inplace=True)
 test_dummies_embarked = pd.get_dummies(df['Embarked'],prefix='Embarked')
 df = pd.concat([df,test_dummies_embarked],axis=1)
 df['Cabin'].fillna('X',inplace=True)
 df['Cabin_clean'] = df['Cabin'].apply(lambda x:x[0])
 test_dummies_cabin = pd.get_dummies(df['Cabin_clean'],prefix='Cabin')
 df = pd.concat([df,test_dummies_cabin],axis=1)
 sex_dict = dict(zip(df['Sex'].unique() ,range(0,2)))
 df['Sex'] = df['Sex'].map(sex_dict)
 test_dummies_pclass = pd.get_dummies(df['Pclass'],prefix='Pclass')
 df = pd.concat([df,test_dummies_pclass],axis=1)
 df['Family'] = df['Parch'] + df['SibSp'] + 1
df['Family_single'] = df['Family'].map(lambda x: 1 if x==1 else 0)
 df['Family_small'] = df['Family'].map(lambda x: 1 if 2<=x<4 else 0)
 df['Family_large'] = df['Family'].map(lambda x: 1 if x>=4 else 0)
 df.drop(['Name','Pclass','Ticket','Cabin','Cabin_clean',\
'Embarked','Title'],axis=1,inplace=True)
 return(df)
<set_options>
train_inputs = torch.tensor(train_inputs)
 validation_inputs = torch.tensor(validation_inputs)
 train_labels = torch.tensor(train_labels)
 validation_labels = torch.tensor(validation_labels)
 train_masks = torch.tensor(train_masks)
 validation_masks = torch.tensor(validation_masks )
%matplotlib inline
sns.set_style('white')
<load_from_csv>
batch_size = 32
train_data = TensorDataset(train_inputs, train_masks, train_labels)
 train_sampler = RandomSampler(train_data)
 train_dataloader = DataLoader(train_data, sampler=train_sampler, batch_size=batch_size)
 validation_data = TensorDataset(validation_inputs, validation_masks, validation_labels)
 validation_sampler = SequentialSampler(validation_data)
 validation_dataloader = DataLoader(validation_data, sampler=validation_sampler, batch_size=batch_size)
df_train = pd.read_csv('.. /input/train.csv')
 df_test = pd.read_csv('.. /input/test.csv' )<prepare_x_and_y>
model = BertForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=5)
 model.cuda()
df_train = feature_engg_train(df_train)
 df_test = feature_engg_test(df_test)
 features_train = df_train.drop(['Survived','Cabin_T'],axis=1)
 target_train = df_train['Survived']
features_test = df_test<train_model>
param_optimizer = list(model.named_parameters())
 no_decay = ['bias', 'gamma', 'beta']
optimizer_grouped_parameters = [
{'params': [p for n, p in param_optimizer if not any(nd in n for nd in no_decay)],
'weight_decay_rate': 0.01},
{'params': [p for n, p in param_optimizer if any(nd in n for nd in no_decay)],
'weight_decay_rate': 0.0}
]
clf=RandomForestClassifier(n_estimators=100,random_state=42)
 clf=clf.fit(features_train,target_train )<categorify>
optimizer = BertAdam(optimizer_grouped_parameters,
lr=2e-5,
warmup=.1 )
model = SelectFromModel(clf, prefit=True,threshold='median')
 train_reduced = model.transform(features_train)
 train_reduced.shape<train_on_grid>
def flat_accuracy(preds, labels):
pred_flat = np.argmax(preds, axis=1 ).flatten()
labels_flat = labels.flatten()
return np.sum(pred_flat == labels_flat)/ len(labels_flat )
X_train,X_test,y_train,y_test = train_test_split(train_reduced,target_train,random_state=42)
 param_grid_rf = {'n_estimators':[100,500],'min_samples_split':[2,5],\
'max_depth':[5,10],'min_samples_leaf':[5,10]}
grid_rf = GridSearchCV(estimator=RandomForestClassifier(random_state=42, oob_score=True, warm_start=True),param_grid=param_grid_rf,cv=10)
 grid_rf.fit(X_train,y_train )<find_best_params>
train_loss_set = []
epochs = 4
for _ in trange(epochs, desc="Epoch"):
model.train()
tr_loss = 0
nb_tr_examples, nb_tr_steps = 0, 0
for step, batch in enumerate(train_dataloader):
batch = tuple(t.to(device)for t in batch)
 b_input_ids, b_input_mask, b_labels = batch
optimizer.zero_grad()
loss = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask, labels=b_labels)
 train_loss_set.append(loss.item())
 loss.backward()
optimizer.step()
tr_loss += loss.item()
nb_tr_examples += b_input_ids.size(0)
 nb_tr_steps += 1
print("Train loss: {}".format(tr_loss/nb_tr_steps))
model.eval()
eval_loss, eval_accuracy = 0, 0
nb_eval_steps, nb_eval_examples = 0, 0
for batch in validation_dataloader:
batch = tuple(t.to(device)for t in batch)
 b_input_ids, b_input_mask, b_labels = batch
with torch.no_grad() :
logits = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask)
 logits = logits.detach().cpu().numpy()
label_ids = b_labels.to('cpu' ).numpy()
tmp_eval_accuracy = flat_accuracy(logits, label_ids)
 eval_accuracy += tmp_eval_accuracy
nb_eval_steps += 1
print("Validation Accuracy: {}".format(eval_accuracy/nb_eval_steps))
print("Best parameters : {}".format(grid_rf.best_params_))
print("Best cross-validation score : {:.2f}".format(grid_rf.best_score_))<save_to_csv>
test = pd.read_csv(".. /input/test.tsv", sep='\t')
 test_id = test['PhraseId']
clf_rf = grid_rf.best_estimator_
clf_rf.fit(train_reduced,target_train)
 target_test = clf_rf.predict(test_reduced)
 df_test['Survived'] = target_test
df_test[['PassengerId','Survived']].to_csv('rf-kaggle-submit.csv',index=False )<load_from_csv>
sentences = test.Phrase.values
sentences = ["[CLS] " + sentence + " [SEP]" for sentence in sentences]
tokenized_texts = [tokenizer.tokenize(sent)for sent in sentences]
train = pd.read_csv('.. /input/train.csv')
 train['SalePrice'] = np.log1p(train['SalePrice'])
 test = pd.read_csv('.. /input/test.csv')
 sub = pd.read_csv('.. /input/sample_submission.csv')
 print(train.shape, test.shape )<data_type_conversions>
MAX_LEN = 32
input_ids = pad_sequences([tokenizer.convert_tokens_to_ids(txt)for txt in tokenized_texts],
maxlen=MAX_LEN, dtype="long", truncating="post", padding="post")
 input_ids = [tokenizer.convert_tokens_to_ids(x)for x in tokenized_texts]
input_ids = pad_sequences(input_ids, maxlen=MAX_LEN, dtype="long", truncating="post", padding="post")
 attention_masks = []
for seq in input_ids:
seq_mask = [float(i>0)for i in seq]
attention_masks.append(seq_mask )
col = [c for c in train.columns if c not in ['Id', 'SalePrice']]
train['null_count'] = np.sum(( train[col]==np.nan ).values, axis=1)
 test['null_count'] = np.sum(( test[col]==np.nan ).values, axis=1)
 for c in col:
train[c + '_null'] =(train[c]==np.nan ).astype(int)
 test[c + '_null'] =(test[c]==np.nan ).astype(int)
 if train[c].dtype == 'O':
lbl0 = {k: v for k, v in train.groupby(by=[c], as_index=False)['SalePrice'].mean().values}
lbl1 = {k: v for k, v in train.groupby(by=[c], as_index=False)['SalePrice'].max().values}
lbl2 = {k: v for k, v in train.groupby(by=[c], as_index=False)['SalePrice'].min().values}
lbl3 = {k:v for v, k in enumerate(train[c].value_counts().index)}
lbl4 = {k: np.log1p(v)for k, v in train[c].value_counts().reset_index().values}
lbl5 = {k:v for v, k in enumerate(pd.concat(( train[c], test[c])).value_counts().index)}
lbl6 = {k: np.log1p(v)for k, v in pd.concat(( train[c], test[c])).value_counts().reset_index().values}
if len(lbl1)>100:
for k in lbl1:
train[c+'_'+str(k)] =(train[c] == k ).astype(int)
 test[c+'_'+str(k)] =(test[c] == k ).astype(int)
 for i in range(6):
train[c+'_key_'+str(i)] = train[c].map(eval('lbl'+str(i)))
 test[c+'_key_'+str(i)] = test[c].map(eval('lbl'+str(i)))
 train[c] = train[c].map(lbl6)
 test[c] = test[c].map(lbl6)
 else:
slope, intercept, r_value, p_value, std_err = stats.linregress(train[c],train['SalePrice'])
 train[c+'_slope'] = train[c] * slope
test[c+'_slope'] = test[c] * slope
train[c+'_log1p'] = np.log1p(train[c])
 test[c+'_log1p'] = np.log1p(test[c])
 train.fillna(-1, inplace=True)
 test.fillna(-1, inplace=True)
 feature_cnt = 25
col = [c for c in train.columns if c not in ['Id', 'SalePrice']]
dim_reduction_pca = decomposition.PCA(n_components=feature_cnt, random_state=10)
 dim_reduction_svd = decomposition.TruncatedSVD(n_components=feature_cnt, random_state=11)
 dim_reduction_pca_train = dim_reduction_pca.fit_transform(train[col])
 dim_reduction_svd_train = dim_reduction_svd.fit_transform(train[col])
 dim_reduction_pca_test = dim_reduction_pca.transform(test[col])
 dim_reduction_svd_test = dim_reduction_svd.transform(test[col])
 for i in range(feature_cnt):
train['dim_reduction_pca_'+str(i)] = dim_reduction_pca_train[:,i]
test['dim_reduction_pca_'+str(i)] = dim_reduction_pca_test[:,i]
train['dim_reduction_svd_'+str(i)] = dim_reduction_svd_train[:,i]
test['dim_reduction_svd_'+str(i)] = dim_reduction_svd_test[:,i]
print(train.shape, test.shape )<split>
test['Sentiment'] = 0
labels = test.Sentiment.values
col = [c for c in train.columns if c not in ['Id', 'SalePrice']]
col = [c for c in col if train[c].dtype != 'O']
x1, x2, y1, y2 = train_test_split(train[col].fillna(-1), train['SalePrice'], test_size=0.2, random_state=3)
 etr = ExtraTreesRegressor(n_jobs=-1, random_state=3)
 etr.fit(x1, y1)
 print(np.sqrt(metrics.mean_squared_error(y2, etr.predict(x2))))
feature_importances = pd.DataFrame({'features':col, 'importance': etr.feature_importances_} ).sort_values(by=['importance'], ascending=False)
 feature_importances.head()<feature_engineering>
prediction_inputs = torch.tensor(input_ids)
 prediction_masks = torch.tensor(attention_masks)
 prediction_labels = torch.tensor(labels)
 batch_size = 32
d_imp = {k:v for k, v in feature_importances.values}
def f_hl_test(a):
q1 = a.quantile(0.25)
 q3 = a.quantile(0.75)
 iqr = q3 - q1
iqr_h = q3 + iqr*1.5
iqr_l = q1 - iqr*1.5
return iqr_l, iqr_h
train['outlier'] = 0.0
test['outlier'] = 0.0
for c in feature_importances.features:
l, h = f_hl_test(train[c])
 train['outlier'] +=(((train[c] < l ).astype(int)+(train[c] > h ).astype(int)) > 0 ).astype(int)* d_imp[c]
test['outlier'] +=(((test[c] < l ).astype(int)+(test[c] > h ).astype(int)) > 0 ).astype(int)* d_imp[c]
print(train.shape, test.shape )<predict_on_test>
prediction_data = TensorDataset(prediction_inputs, prediction_masks, prediction_labels)
 prediction_sampler = SequentialSampler(prediction_data)
 prediction_dataloader = DataLoader(prediction_data, sampler=prediction_sampler, batch_size=batch_size )
sk_if = IsolationForest(n_jobs=-1, random_state=3)
 sk_lof = LocalOutlierFactor(novelty=True, n_jobs=-1)
 train['outlier_sk_if'] = sk_if.fit_predict(train[col].fillna(-1), train['SalePrice'])
 sk_lof.fit(train[col].fillna(-1), train['SalePrice'])
 train['outlier_sk_lof'] = sk_lof.predict(train[col].fillna(-1))
test['outlier_sk_if'] = sk_if.predict(test[col].fillna(-1))
test['outlier_sk_lof'] = sk_lof.predict(test[col].fillna(-1))<save_to_csv>
model.eval()
predictions , true_labels = [], []
for batch in prediction_dataloader:
batch = tuple(t.to(device)for t in batch)
 b_input_ids, b_input_mask, b_labels = batch
with torch.no_grad() :
logits = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask)
 logits = logits.detach().cpu().numpy()
label_ids = b_labels.to('cpu' ).numpy()
predictions.append(logits)
col = [c for c in train.columns if c not in ['Id', 'SalePrice']]
data = simple.Data(train, test, 'Id', 'SalePrice')
 params = {'learning_rate': 0.005, 'max_depth': -1, 'boosting': 'gbdt', 'objective': 'regression', 'metric':'rmse', 'seed': 3, 'num_iterations': 5000, 'early_stopping_round': 200, 'verbose_eval': 300, 'num_leaves': 64, 'feature_fraction': 0.8, 'bagging_fraction': 0.8, 'bagging_freq': 5}
sub = simple.Model(data, 'LGB', params, 0.2, 7 ).PRED
sub['SalePrice'] = np.expm1(sub['SalePrice'])
 sub.to_csv('submission_lgb.csv', index=False )<save_to_csv>
preds = np.concatenate(predictions )
lr = linear_model.Ridge(random_state=3)
 lr.fit(train[col], train['SalePrice'])
 print('Ridge', np.sqrt(metrics.mean_squared_error(train['SalePrice'], lr.predict(train[col]))))
test['SalePrice'] = np.expm1(lr.predict(test[col]))
test[['Id','SalePrice']].to_csv('submission_ridge.csv', index=False)
 sub = simple.Blend(['submission_lgb.csv', 'submission_ridge.csv'], 'Id', 'SalePrice' ).BLEND.reset_index()<merge>
labels = np.argmax(preds, axis =1)
<split><EOS> 
submission = pd.DataFrame({'PhraseId': test_id, 'Sentiment': labels})
 submission.to_csv('submission.csv', index=False)
 submission.head()