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
Step: 1
import time import pandas as pd from sklearn import linearmodel impor...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started