Last active
June 12, 2017 11:07
-
-
Save jay-trivedi/5e51b5ce3aa9886f88af190d4afc3768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
depth = 10 | |
seed_range = range(0, 3000,288) | |
acc_vs_seed_result_rf = {"seed": [],\ | |
"train_acc": [], | |
"valid_acc": [], | |
"top_feature": [], | |
"second_feature": [], | |
"third_feature": []} | |
for seed in seed_range: | |
model = H2ORandomForestEstimator(model_id="model", \ | |
sample_rate=0.7, \ | |
ntrees=200, \ | |
max_depth=depth, \ | |
seed=seed) | |
model.train(x=x, y=y, training_frame=train) | |
predict_valid = model.predict(valid[x]) | |
predict_train = model.predict(train[x]) | |
t = predict_train["predict"].cbind(train["SalePrice"]).as_data_frame() | |
v = predict_valid["predict"].cbind(valid["SalePrice"]).as_data_frame() | |
acc_vs_seed_result_rf["seed"].append(seed) | |
acc_vs_seed_result_rf["valid_acc"].append(mean_squared_error(y_true = v.SalePrice, y_pred = v.predict)) | |
acc_vs_seed_result_rf["train_acc"].append(mean_squared_error(y_true = t.SalePrice, y_pred = t.predict)) | |
acc_vs_seed_result_rf["top_feature"].append(model.varimp()[0][0]) | |
acc_vs_seed_result_rf["second_feature"].append(model.varimp()[1][0]) | |
acc_vs_seed_result_rf["third_feature"].append(model.varimp()[2][0]) | |
#Converting resuts to a DataFrame | |
acc_vs_seed_result_df_rf = pd.DataFrame(acc_vs_seed_result_rf) | |
cols = ["seed", "train_acc", "valid_acc", "top_feature", "second_feature", "third_feature"] | |
acc_vs_seed_result_df_rf = acc_vs_seed_result_df_rf[cols] | |
acc_vs_seed_result_df_rf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment