欠拟合和过拟合的概念比较好理解,造成欠拟合和过拟合的因素有多种多样的,两者的共性都是具有较差的泛化能力。本次通过模型选择的方法来显示泛化能力。
- 使用三阶段多项式来创造样本
import gluonbook as gb
from mxnet import autograd,nd,gluon
from mxnet.gluon import data as gdata,loss as gloss,nn
%matplotlib inline
#生成数据集
n_train,n_test,true_w,true_b = 100,100,[1.2,-3.4,5.6],5
features = nd.random.normal(scale = 1,shape = (n_train + n_test,1))
plot_features = nd.concat(features,nd.power(features,2),nd.power(features,3))
labels = true_w[0] * plot_features[:,0] + true_w[1] * plot_features[:,1] + true_w[2] * plot_features[:,2] + true_b
labels += nd.random.normal(scale = 0.1,shape = labels.shape)
#定义、训练和测