机器学习作业---偏差和方差(线性回归)
机器学习作业---偏差和方差(线性回归)错误反例,但是理清了代码思路,很重要 一:加载数据,显示数据 (一)数据可视化 import numpy as np import matplotlib.pyplot as plt import scipy.io as sio import scipy.optimize as opt data = sio.loadmat( " ex5data1.mat " ) X = data[ ' X ' ] y = data[ ' y ' ].flatten() Xval = data[ ' Xval ' ] yval = data[ ' yval ' ].flatten() Xtest = data[ ' Xtest ' ] ytest = data[ ' ytest ' ].flatten() m = y.size plt.figure() plt.scatter(X,y,c = ' b ' ,marker= ' o ' ) plt.xlabel( " Change in water level (x) " ) plt.ylabel( " Water folowing out of the dam (y) " ) plt.show() (二)数据显示 直接从文件中读取的数据X: [[- 15.93675813 ] [ - 29.15297922 ]