在本文,我们将介绍如何通过使用 mxnet
的 api
实现线性回归。
Note:This blog without all the resources that are outside the original,reproduced please indicate the source.
官网指导:mxnet.incubator.apache.org,文中如有任何错漏的地方请谅解并指出,不胜感激.
我们尝试去学习的函数是 : (y = X1 + 2* X2 ),(X1,X2)
是输入特征,Y
是相应的标签.
前提
为了完成教程,我们需要做一下准备:
- 安装好mxnet.(可以看我相关的安装演示)
- 安装Jupyter Notebook
$ pip install jupyter
在实验之前,我们需要导入必要的包,在接下来的练习中会使用到他们.
import mxnet as mx
import numpy as np
import logging
logging.getLogger().setLevel(logging.DEBUG)
准备数据
在mxnet中,数据是通过数据迭代器输入的。在这里,我们将说明如何将数据转化为一个迭代器,MXNet可以使用。示例中使用的数据是由具有相应整数标签的2D
数据点组成的。
#Training data
train_data = np.random.uniform(0, 1, [100, 2])
train_label = np.array([train_data[i][0] + 2 * train_data[i][1] for i in