daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def model_training_xgb(training_data,testing_data):
  2.   # splits train and validation set
  3.   X = training_data.drop(labels=['msno','is_churn'],axis=1)
  4.   Y = training_data['is_churn']
  5.   X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size=0.2,random_state = 2)
  6.   # model
  7.   xgb_watchlist = [(X_train, Y_train), (X_val, Y_val)]
  8.   model = xgb.XGBClassifier(learning_rate=0.08, max_depth=4,n_estimators=300,\
  9.                  subsample=0.5, seed=2,missing=-1)
  10.   model.fit(X_train, Y_train,eval_set=xgb_watchlist,eval_metric='logloss',
  11.             early_stopping_rounds=20,verbose=70)
  12.   # caculating E_val
  13.  
  14.   model_probs = model.predict_proba(X_val)
  15.     # [:,1] to show the prob to is_churn = 1
  16.   model_val_score = log_loss(Y_val,model_probs[:,1])
  17.  
  18.   # predict on testing set
  19.   model_pred_testing_set = model.predict_proba(testing_data.drop(labels=['msno','is_churn'],axis=1))
  20.   model_pred_testing_set = model_pred_testing_set[:,1] # take out the prob if is_churn = 1
  21.   submission = pd.DataFrame({"msno": testing_data.msno})
  22.   submission.insert(1,column='is_churn',value=model_pred_testing_set)
  23.  
  24.   return model, model_val_score, submission
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top