We will need a function that returns one bootstrap sample of the regression fit. That is, it
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 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()
Applied Regression Analysis and Other Multivariable Methods
ISBN: 978-1285051086
5th edition
Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg