Kaggle competition: Homesite Quote Conversion
<SOS> metric: AUC Kaggle data source: homesite-quote-conversion<compute_train_metric>
sns.set_style('whitegrid')
 %matplotlib inline
y_scores = cross_val_predict(
 mnb_clf,
X_train_transformed, y_train_transformed,
cv=5,
verbose=3,
method='predict_proba', 
)
 multiclass_logloss(y_train_transformed, y_scores )<find_best_model_class>
homesite_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/test.csv")
 homesite_df = homesite_df.drop(['QuoteNumber'], axis=1)
 homesite_df['Year'] = homesite_df['Original_Quote_Date'].apply(lambda x: int(str(x)[:4]))
homesite_df['Month'] = homesite_df['Original_Quote_Date'].apply(lambda x: int(str(x)[5:7]))
homesite_df['Week'] = homesite_df['Original_Quote_Date'].apply(lambda x: int(str(x)[8:10]))
test_df['Year'] = test_df['Original_Quote_Date'].apply(lambda x: int(str(x)[:4]))
test_df['Month'] = test_df['Original_Quote_Date'].apply(lambda x: int(str(x)[5:7]))
test_df['Week'] = test_df['Original_Quote_Date'].apply(lambda x: int(str(x)[8:10]))
homesite_df.drop(['Original_Quote_Date'], axis=1,inplace=True)
 test_df.drop(['Original_Quote_Date'], axis=1,inplace=True)
 for f in homesite_df.columns:
if homesite_df[f].dtype=='object':
lbl = preprocessing.LabelEncoder()
lbl.fit(np.unique(list(homesite_df[f].values)+ list(test_df[f].values)))
 homesite_df[f] = lbl.transform(list(homesite_df[f].values))
test_df[f] = lbl.transform(list(test_df[f].values))
stopword_params = [True, False]
vocabulary_params = [7000, 8000, 9000, 10000]
data_scores = []
for stopword, vocabulary in list(itertools.product(stopword_params, vocabulary_params)) :
full_pipeline.set_params(
 text_pipeline__text_to_word_count__remove_stopwords=stopword,
text_pipeline__word_count_to_vector__vocabulary_size=vocabulary, 
)
 X_train_processed = full_pipeline.fit_transform(X_train)
 y_scores = cross_val_predict(
 log_clf,
X_train_processed, y_train_transformed,
cv=3,
method='predict_proba', 
)
 data_scores += [(stopword, vocabulary, multiclass_logloss(y_train_transformed, y_scores)) ]<train_model>
homesite_df.fillna(homesite_df.mean() , inplace=True)
 test_df.fillna(test_df.mean() , inplace=True)
 X_train = homesite_df.drop("QuoteConversion_Flag",axis=1)
 Y_train = homesite_df["QuoteConversion_Flag"]
X_test = test_df.drop("QuoteNumber",axis=1 ).copy()
X_train = maxabs_scale(X_train)
 X_test = maxabs_scale(X_test )
for stopword, vocabulary, logloss in data_scores:
print('remove_stopwords:', stopword, ',', 'vocabulary_size:',vocabulary)
 print('logloss: ', logloss )<categorify>
params = {"objective": "binary:logistic"}
T_train_xgb = xgb.DMatrix(X_train, Y_train)
 X_test_xgb = xgb.DMatrix(X_test)
 gbm = xgb.train(params, T_train_xgb, 20)
 Y_pred = gbm.predict(X_test_xgb )
<train_on_grid><EOS> 
submission = pd.DataFrame()
submission["QuoteNumber"] = test_df["QuoteNumber"]
submission["QuoteConversion_Flag"] = Y_pred
submission.to_csv('homesite.csv', index=False )