Stepwise variable selection
We can use stepwise variable selection (forward, backward, both) in predictive models using the stepAIC()
function for feature selection.
This can be done by executing the following code:
> MultipleR.lm = lm(StockYPrice ~ StockX1Price + StockX2Price + StockX3Price + StockX4Price, data=DataMR) > step <- stepAIC(MultipleR.lm, direction="both") > step$anova
Here, we are using the dataset used for multiple regression as the input dataset. One can also use all-subsets regression using the leaps()
function from the leaps package.
Variable selection by classification
We can use classification techniques such as decision tree or random forest to get the most significant predictors. Here we are using random forest (code is given) to find the most relevant features. All the four attributes in the dataset DataForMultipleRegression1
have been selected in the following example and the plot shows the accuracy of different subset sizes...