Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. # Extra Trees Regressor
  2.  
  3. et_regr = ExtraTreesRegressor()
  4. et_regr.fit(train_df_munged, label_df)
  5.  
  6. # Run prediction on training set to get a rough idea of how well it does.
  7. y_pred = et_regr.predict(train_df_munged)
  8. y_test = label_df
  9. print("Extra Trees Regressor score on training set: ", rmse(y_test, y_pred))
  10.  
  11. # Run prediction on the Kaggle test set.
  12. y_test_pred_et = et_regr.predict(test_df_munged)
  13.  
  14. # Fit model using each importance as a threshold
  15. thresholds = sort(et_regr.feature_importances_)
  16. #thresholds = sort([0.1,0.2])
  17. for thresh in thresholds:
  18. # select features using threshold
  19. selection = SelectFromModel(et_regr, threshold=thresh, prefit=True)
  20. select_X_train = selection.transform(train_df_munged)
  21. # train model
  22. selection_model = ExtraTreesRegressor()
  23. selection_model.fit(select_X_train, y_test)
  24. # eval model
  25. select_X_test = selection.transform(train_df_munged)
  26.  
  27. y_pred = selection_model.predict(select_X_test)
  28. print("Thresh=%.3f, n=%d, RMSE= %.10f" % (thresh, select_X_train.shape[1], rmse(y_test, y_pred)))
  29.  
  30. selection = SelectFromModel(et_regr, threshold=0.01, prefit=True)
  31. select_X_train = selection.transform(train_df_munged)
  32. # train model
  33. selection_model = ExtraTreesRegressor()
  34. selection_model.fit(select_X_train, y_test)
  35. # eval model
  36. select_X_test = selection.transform(test_df_munged)
  37.  
  38. y_test_pred_et_selec = selection_model.predict(select_X_test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement