Exemplo n.º 1
0
score_avg = np.sqrt(pp.score_model(averaged_models, train_X_reduced, train_y))
print(" Averaged base models score: {:.6f} ({:.6f})\n".format(
    score_avg.mean(), score_avg.std()))

averaged_models.fit(train_X_reduced, train_y)
predicted_prices_averaged = np.expm1(averaged_models.predict(test_X_reduced))
print(predicted_prices_averaged)
my_submission = pd.DataFrame({
    'Id': test.Id,
    'SalePrice': predicted_prices_averaged
})
my_submission.to_csv('submission_avg.csv', index=False)

stacked_averaged_models = em.StackingAveragedModels(
    base_models=[model_svr, model_ENet, model_KRR, model_xgb],
    meta_model=model_byr)

score_stacked_averaged = np.sqrt(
    pp.score_model(stacked_averaged_models, train_X_reduced, train_y))
print(" Stacked Averaged base models score: {:.6f} ({:.6f})\n".format(
    score_stacked_averaged.mean(), score_stacked_averaged.std()))

stacked_averaged_models.fit(train_X_reduced, train_y)
predicted_prices_stacked_averaged = np.expm1(
    stacked_averaged_models.predict(test_X_reduced))
print(predicted_prices_stacked_averaged)

model_xgb.fit(train_X_reduced, train_y)
predicted_prices_xgboost = np.expm1(model_xgb.predict(test_X_reduced))
print(predicted_prices_xgboost)
Exemplo n.º 2
0
cross_val_table = get_validation_scores(tree_models, X_train, y_train, 5,
                                        X_test, y_test)
print(cross_val_table)

cross_val_table = get_validation_scores(tree_models, train_X_reduced, train_y,
                                        5)
print(cross_val_table)

cross_val_table_linear = get_validation_scores(linear_models, train_X_reduced,
                                               train_y, 5)
print(cross_val_table_linear)

averaged_models = em.AveragingModels(
    models=[model_lgb, model_byr, model_svr, model_ridge])
stacked_averaged_models = em.StackingAveragedModels(
    base_models=[model_svr, model_lgb], meta_model=model_KRR)
averaged_plus = em.AveragingModels(
    models=[averaged_models, model_GBoost, model_xgb], weights=[0.7, 0.2, 0.1])
averaged_plus_plus = em.AveragingModels(
    models=[stacked_averaged_models, model_GBoost, model_xgb],
    weights=[0.7, 0.2, 0.1])

ensemble_models = []
ensemble_models.append(("averaged", averaged_models))
ensemble_models.append(("stacked", stacked_averaged_models))
ensemble_models.append(("averaged_plus", averaged_plus))
ensemble_models.append(("averaged_plus_plus", averaged_plus_plus))

cross_val_table_ensemble = get_validation_scores(ensemble_models, X_train,
                                                 y_train, X_test, y_test)
print(cross_val_table_ensemble)