Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

I need help with 5-fold cross validation in python without using sklearn. Next, you need to use **5-fold cross validation** to pick out the best

I need help with 5-fold cross validation in python without using sklearn.

Next, you need to use **5-fold cross validation** to pick out the best model for the prediction. You should present a chart of the error function $J$, similar to the one in the lecture (see below). You may need to use package like "**tabulate**" to print out the table.

This is the contents of the textfile: the first two numbers are m for lines of data and n for number of features.

19 1 28 12.2 32 11.9 36 11.5 48 11.9 52 11.5 56 11.5 60 11.0 64 11.4 68 11.0 72 11.07 76 11.08 80 11.06 84 10.97 88 10.54 92 10.82 96 10.94 100 11.12 104 10.93 108 10.78

You read in the first column as x and the second as y. Then turn the the x array into a 2D array like [[1 28]

1 32] etc. Then you must find J(w0,w1) as well as the weight and fold the data into equal folds [1-5]. You then must take the 5 fold as the test set and the rest of the fold into training set. With those sets you must use a linear, Quadratic, Cubic, and fourth equation to get the mean using Jw(x) on each sub model

This is what should be the output.

image text in transcribed

You need to plot your training and testing J with respect to the polynomial degree, similar to the one in the lecture. With this data you do 5-fold cross validation to get the means shown above.

\begin{tabular}{lrrrr} & Linear & Quadratic & Cubic & Fourth \\ \hline 1234 & 10.25 & 24.25 & 12.25 & 23.25 \\ 5 & 10.25 & 19.25 & 14.25 & 23.25 \\ 1235 & 10.25 & 15.25 & 19.25 & 23.25 \\ 4 & 10.25 & 10.25 & 20.25 & 23.25 \\ 1245 & 10.25 & 24.25 & 12.25 & 23.25 \\ 3 & 10.25 & 19.25 & 14.25 & 23.25 \\ 1345 & 10.25 & 24.25 & 12.25 & 23.25 \\ 2 & 10.25 & 19.25 & 14.25 & 23.25 \\ 2345 & 10.25 & 24.25 & 12.25 & 23.25 \\ 1 & 10.25 & 19.25 & 14.25 & 23.25 \\ Mean for Training & 0 & 0 & 0 & 0 \\ Mean for Testing & 0 & 0 & 0 & 0 \end{tabular}

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_2

Step: 3

blur-text-image_3

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students explore these related Databases questions