Using Python,  Create a k-fold cross validation code with the number of folds being 10. The raw data needs to be split into training and testing. The number of folds is the number of times you should go through a for loop. Inside of the for loop, index into your raw data to pull out training and testing data based on the fold (think about how the folds are organized and how much data is in each fold, which is based on the total number of folds) Do normal linear regression model fitting Keep track of the R^2 scores of the folds Print the average and standard deviation of the R^2 value for the different folds

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Using Python, 

Create a k-fold cross validation code with the number of folds being 10.
  1. The raw data needs to be split into training and testing.
  2. The number of folds is the number of times you should go through a for loop.
  3. Inside of the for loop, index into your raw data to pull out training and testing data based on the fold (think about how the folds are organized and how much data is in each fold, which is based on the total number of folds)
  4. Do normal linear regression model fitting
  5. Keep track of the R^2 scores of the folds
  6. Print the average and standard deviation of the R^2 value for the different folds
Our libraries that we are importing:
# 1a. Importing all the libraries necessary for this assignment
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
[7] # 1b. Loading the data
data = sns.load_dataset('geyser')
Let's check out this dataset.
[9] print('
data
1
duration waiting kind
3.600
79
long
1
1.800
54 short
2
3.333
74
long
3
2.283
62 short
4
4.533
85
long
267
4.117
81
long
268
2.150
46 short
269
4.417
90
long
270
1.817
46 short
271
4.467
74
long
272 rows x 3 columns
Imagine working at Yellowstone National Park as a scientist researching Old Faithful Geyser. The boss wants us to evaluate the predictiveness
of the relationship between duration of an eruption in minutes ("duration") and the duration in minutes until the next eruption ("waiting"). We
collected the data, but the internet in Yellowstone is not very good, so we cannot access the crossvalidation library in python
Transcribed Image Text:Our libraries that we are importing: # 1a. Importing all the libraries necessary for this assignment import seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression [7] # 1b. Loading the data data = sns.load_dataset('geyser') Let's check out this dataset. [9] print(' data 1 duration waiting kind 3.600 79 long 1 1.800 54 short 2 3.333 74 long 3 2.283 62 short 4 4.533 85 long 267 4.117 81 long 268 2.150 46 short 269 4.417 90 long 270 1.817 46 short 271 4.467 74 long 272 rows x 3 columns Imagine working at Yellowstone National Park as a scientist researching Old Faithful Geyser. The boss wants us to evaluate the predictiveness of the relationship between duration of an eruption in minutes ("duration") and the duration in minutes until the next eruption ("waiting"). We collected the data, but the internet in Yellowstone is not very good, so we cannot access the crossvalidation library in python
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY