Question: add 10-fold cross validation and estimate test error per each test fold, calculate the average error of of the 10 errors. import tensorflow as tf
add 10-fold cross validation and estimate test error per each test fold, calculate the average error of of the 10 errors.
import tensorflow as tf import numpy as np xy np.loadtxt('auto-mpg.csv', delimiterdtypenp.float32) datax xy[10:, 1: exclude the first column, which is the target value, mpg datay xy[10:, [0]mpg column testX-xy[0:10,1:lt testy xy [ 0 : 10.. [ 0 ] ]-# xtf.placeholder (tf.float32, shape [None, 7] ytf.placeholder (tf.float32, shape [None, 1] Wtf.Variable (tf.random_normal ([7, 1]), name- 'weight') b tf.Variable (tf. random normal( [1]), name='bias') hypothesis-tf.matmul (x, W) + b cost-tf.reduce mean (tf.square (hypothesis- y)) optimizertf.train.GradientDescentoptimizer (learning rate-o.0000001) trainoptimizer.minimize (cost) sess = tfSession() sess.run (tf.global_variables_initializer )) for step in range (20000): -'-c-sess.run ( [ train, if step % 100-0: cost], feed-dict={X: da tax, y: datay}) print (step, _c,sess.run (W)) print (sess.run (cost, feed dict-(X: testX, y: testy))) import tensorflow as tf import numpy as np xy np.loadtxt('auto-mpg.csv', delimiterdtypenp.float32) datax xy[10:, 1: exclude the first column, which is the target value, mpg datay xy[10:, [0]mpg column testX-xy[0:10,1:lt testy xy [ 0 : 10.. [ 0 ] ]-# xtf.placeholder (tf.float32, shape [None, 7] ytf.placeholder (tf.float32, shape [None, 1] Wtf.Variable (tf.random_normal ([7, 1]), name- 'weight') b tf.Variable (tf. random normal( [1]), name='bias') hypothesis-tf.matmul (x, W) + b cost-tf.reduce mean (tf.square (hypothesis- y)) optimizertf.train.GradientDescentoptimizer (learning rate-o.0000001) trainoptimizer.minimize (cost) sess = tfSession() sess.run (tf.global_variables_initializer )) for step in range (20000): -'-c-sess.run ( [ train, if step % 100-0: cost], feed-dict={X: da tax, y: datay}) print (step, _c,sess.run (W)) print (sess.run (cost, feed dict-(X: testX, y: testy)))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
