Question: 1 0 . 7 LAB: Random Forests for Regression and Classification You will use the same mpg . csv dataset for the following tasks. Load
LAB: Random Forests for Regression and Classification
You will use the same mpg csv dataset for the following tasks.
Load the mpg csv dataset.
Create a feature dataframe, using weight, modelyear, and horsepower features.
Create a target dataframe, using the mpg feature.
will contain the continuous mpg values for the regression model.
For the classification model, create a new column mpgclasses in that categorizes mpg values as low: medium: and high: and above
Initialize a Random Forest Regressor with: nestimators randomstate maxdepth minsamplesleaf
Fit this model on the and the mpg column in y
Print Feature importances and Mean Squared Error MSE
Initialize a Random Forest Classifier with the same parameters as for the regression model.
Fit this model on the x and the mpgclasses column in y
Print Feature importances and classification accuray
i am posting the whole question for full reference i really only need help with creating the new column for Y for the classification model which is the code shown at the bottom of the screenshot
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
