Answered step by step
Verified Expert Solution
Link Copied!

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 cross-validation with
=10. Use the negative of the cross_val_score() method with the following parameters, respectively:
the model variable
x_variable
y_variable
the scoring parameter set to neg_mean_squared_error
the cv parameter set to 10
Both x_variable and y_variable 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 cross-validation, and prints average MSE and the set of all MSEs for both 10-fold and
-fold cross-validation.# Import packages and functions
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.model_selection import train_test_split, cross_val_score
rng = np.random.RandomState(46)
# Load the dataset
pines = pd.read_csv('pinesSample.csv')
# Split dataset into training data and testing data
trainDataName, testDataName = train_test_split(pines, test_size=0.2, random_state=rng)
# Store relevant columns as variables
X = trainDataName[['age']]
y = trainDataName[['height']]
# Initialize the model -- quadratic polynomial regression model
polyFeatures = PolynomialFeatures(degree=2, include_bias=False)
xPoly = polyFeatures.fit_transform(X)
polyRegModel = LinearRegression()
# Evaluate accuracy
# neg_mean_square_error is the negative MSE, so append a minus so the scores are positive.
tenFoldScores = # Your code goes here
print('ten-fold average MSE =', np.mean(tenFoldScores),'
', tenFoldScores)
# neg_mean_square_error is the negative MSE, so append a - so the scores are positive.
LOOCVScores =-cross_val_score(polyRegModel, X, y, scoring='neg_mean_squared_error', cv=len(X))
print('
k-fold average MSE =', np.mean(LOOCVScores),'
', LOOCVScores)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

=+What can I do to make this press worthy?

Answered: 1 week ago