Voting Ensemble Model
By using the [voting ensemble model], we can learn multiple models respectively and compare the results.
from sklearn.linear_model import LinearRegression as lr
from xgboost import XGBRegressor as xgb
from sklearn.ensemble import RandomForestRegressor as rfr
from sklearn.ensemble import GradientBoostingRegressor as grb
from sklearn.ensemble import VotingRegressor
import joblib
import time
model_list=[lr(), rfr(), grb(), xgb()]
# Convert mutli dimension array to single dimension array.
train_y = train_y.to_numpy().flatten()
# Save several models after learning sequence.
model_result = []
for i in range(len(model_list)):
model = model_list[i]
model.fit(train_x, train_y)
pred_y = model.predict(test_x)
model_result.append(model)
# Models list
voting_models = [
('linear_reg', model_rslt[0]),
('randForest', model_rslt[1]),
('gradBoost', model_rslt[2]),
('xgboost', model_rslt[3])
]
# Run VotingRegressor
voting_regressor = VotingRegressor(voting_models, n_jobs=-1)
voting_regressor.fit(train_x, train_y)
pred_y = voting_regressor.predict(test_x)
Comments
Post a Comment