Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Researchers collected measurements from loblolly pines. Calculate the mean squared errors for - fold cross - validation with = 1 0 . Use the negative
Researchers collected measurements from loblolly pines.
Calculate the mean squared errors for
fold crossvalidation with
Use the negative of the crossvalscore method with the following parameters, respectively:
the model variable
xvariable
yvariable
the scoring parameter set to negmeansquarederror
the cv parameter set to
Both xvariable and yvariable are from the training set.
The code provided contains all imports, loads the dataset, splits the dataset into train and test datasets, initializes the model, calculates the MSEs for
fold crossvalidation, and prints average MSE and the set of all MSEs for both fold and
fold crossvalidation.# Import packages and functions
import pandas as pd
import numpy as np
from sklearn.linearmodel import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.modelselection import traintestsplit, crossvalscore
rng nprandom.RandomState
# Load the dataset
pines pdreadcsvpinesSamplecsv
# Split dataset into training data and testing data
trainDataName, testDataName traintestsplitpines testsize randomstaterng
# Store relevant columns as variables
X trainDataNameage
y trainDataNameheight
# Initialize the model quadratic polynomial regression model
polyFeatures PolynomialFeaturesdegree includebiasFalse
xPoly polyFeatures.fittransformX
polyRegModel LinearRegression
# Evaluate accuracy
# negmeansquareerror is the negative MSE, so append a minus so the scores are positive.
tenFoldScores # Your code goes here
printtenfold average MSE npmeantenFoldScores
tenFoldScores
# negmeansquareerror is the negative MSE, so append a so the scores are positive.
LOOCVScores crossvalscorepolyRegModel X y scoring'negmeansquarederror', cvlenX
print
kfold average MSE npmeanLOOCVScores
LOOCVScores
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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