Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I need help to do the below question, it is about Forward Stepwise Refinement. I had tried few different codes, but also get wrong.

Hi, I need help to do the below question, it is about Forward Stepwise Refinement. I had tried few different codes, but also get wrong. And my last code is below.

Requested by the assignment:

Forward Stepwise Refinement:

You will manually perform the steps of the forward stepwise selection method for four parameters. You will do this following Algorithm 6.2 from ISLR. For =14k=14:

Set up a regression model with k factors that involves the fixed predictors from the previous step 1k1

Try all p predictors in the new kth position

Select the best parameter using Adjusted2AdjustedR2 (e.g. model.rsquared_adj) given your training data

Fix the new parameter and continue the process for +1k+1

Then, you will construct a plot similar to the one above, plotting the Adjusted2AdjustedR2 for each of your k steps and plotting the Adjusted2AdjustedR2 from the test set using that model.

I had done the below two request question, and it is correct.

from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler train_fat, test_fat = train_test_split(cfat, test_size=0.2, random_state=42) observation_count = 125 train_fat, test_fat = train_test_split(cfat, test_size = observation_count/cfat.shape[0], random_state=42)
best = ['',0] for p in allowed_factors: model = smf.ols(formula='Density~'+p, data=train_fat).fit() print(p, model.rsquared) if model.rsquared>best[1]: best = [p, model.rsquared] print('best:',best)

After the above code was correct, now have to do the below question for Forward Stepwise.

In the following exercises, you can not use the Density, Fat or BMI columns in your predictive models. You can only use the 13 predictors in the allowed_factors list.

In [55]:

allowed_factors = ['Age', 'Weight', 'Height', 'Neck', 'Chest', 'Abdomen', 'Hip', 'Thigh', 'Knee', 'Ankle', 'Biceps', 'Forearm', 'Wrist']

The Question here:

3d. Conduct the algorithm above for =1k=1, leaving your best solution as the answer [5 pts]

Call your resulting model train_bmi1.

My Answer:

y_col=cfat['Abdomen'] x_col=cfat[['Weight','Chest','Hip','Thigh']] 
best=['',0] for p in x_col: train_bmi1 = smf.ols(formula='Abdomen~'+p, data=test_fat).fit() print(p, train_bmi1.rsquared_adj)

The results:

AssertionError: Check 3d. Look at the parameters of train_bmi1.

I don't know how to do the above 3d question. Please help me and guide me. Thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago

Question

6. Are my sources reliable?

Answered: 1 week ago

Question

5. Are my sources compelling?

Answered: 1 week ago