Model specification
The stepAIC()
function gives back a reduced model, as you just saw in the previous video. Now you want to apply this method to the exercise dataset defaultData
.
The prepared dataset is available in your environment. Additionally, the MASS
package is loaded and the previously built logit model logitModelFull
is defined for you. Also note that we've reduced the size of the dataset as performing stepwise model selection can take a long time with larger datasets and more complex models.
Este exercício faz parte do curso
Machine Learning for Marketing Analytics in R
Instruções do exercício
- Make use of the
stepAIC()
function. Settrace = 0
, as you do not want to get an output for the whole model selection process. Save the result to the objectlogitModelNew
. - Then, use the
summary()
function to take a look atlogitModelNew
. You can ignore the warning message in this case. Go ahead and see what changed. Understand the results. - The formula is saved in an object so that you don't have to type the whole equation again when you want to use it later.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
library(MASS)
# The old (full) model
logitModelFull <- glm(PaymentDefault ~ limitBal + sex + education + marriage +
age + pay1 + pay2 + pay3 + pay4 + pay5 + pay6 + billAmt1 +
billAmt2 + billAmt3 + billAmt4 + billAmt5 + billAmt6 + payAmt1 +
payAmt2 + payAmt3 + payAmt4 + payAmt5 + payAmt6,
family = binomial, defaultData)
#Build the new model
logitModelNew <- stepAIC(___,___)
#Look at the model
summary(logitModelNew)
# Save the formula of the new model (it will be needed for the out-of-sample part)
formulaLogit <- as.formula(summary(logitModelNew)$call)
formulaLogit