- In In The Initial Model Is The Constant Model This Requires Special Handling In Train Model And Score Mode 1 (89.04 KiB) Viewed 21 times
In [ ]: In [ ]: # The initial model is the constant model this requires special handling # in train_model and score_mode
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
In [ ]: In [ ]: # The initial model is the constant model this requires special handling # in train_model and score_mode
In [ ]: In [ ]: # The initial model is the constant model this requires special handling # in train_model and score_model def train_model(variables): if len(variables) == 0: return None model Linear Regression () model.fit(train_X[variables], train_y) return model def score_model(model, variables): if len(variables) == 0: return AIC_score(train_y, [train_y.mean()]* len(train_y), model, df=1) return AIC_score (train_y, model.predict(train_X[variables]), model) best_model, best_variables = forward_selection (train_X.columns, train_model, score_model, verbose=True) print (best_variables) 8. Write the components of the final model from forward selection below. Compare the best model with those generated by backward elimination and exhaustive search. Is there any difference? Why? best_model, best_variables = stepwise_selection (train_X.columns, train_model, score_model, verbose=True) print (best_variables) 9. Write the components of the final model from stepwise selection below. Compare the best model with those generated by forward selection, backward elimination, and exhaustive search. Is there any difference? Why?