Question: 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

1 Expert Approved Answer
Step: 1 Unlock

import time import pandas as pd from sklearn import linearmodel impor... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!