Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We will need a function that returns one bootstrap sample of the regression fit. That is, it resamples the dataset with replacement, then fits a

We will need a function that returns one bootstrap sample of the regression fit. That is, it resamples the dataset with replacement, then fits a linear regression to the data. Fill in the code below to complete the function

 

def get_one_bootstrap_salary_fit():
   import time
   import pandas as pd
   from sklearn import linear_model
   import numpy as np

   import operator
   from sklearn.linear_model import LinearRegression

 

   '''
   Returns a sklearn.linear_model.LinearRegression model representing
   a fit to a bootstrap-resampled version of salary_df
   '''
   
   #resample the data with replacement (replace=True) to a data frame with
   #the same number of data points (frac=1.0)


   resampled_df = salary_df.sample(frac=1.0, replace=True)

 

   #fit model to resampled data
   X = resampled_df[['YearsExperience']] #[[ ]] subsets so X remains a DataFrame
   y = resampled_df['Salary']       #y should be an array, so we use [ ]
   
   # insert code below using LinearRegression to return a linear regression model
   # with predictor X and outcome variable y


   # YOUR CODE HERE


   #raise NotImplementedError()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import time import pandas as pd from sklearn import linearmodel impor... 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

Applied Regression Analysis And Other Multivariable Methods

Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg

5th Edition

1285051084, 978-1285963754, 128596375X, 978-1285051086

More Books

Students also viewed these Programming questions

Question

Explain the factors that influence peoples values.

Answered: 1 week ago