深度学习之简单线性回归(1)

本文通过实例介绍了深度学习中的简单线性回归,采用二维特征和二次损失函数,利用SGD进行梯度下降优化,迭代次数为3次,并在运行中生成相关图表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这篇文章主要还是针对于简单的线性回归的复现,使用的线性回归二维特征,损失函数是二次函数,采用SGD梯度下降来迭代。迭代周期数是3。注释在代码中有写。

#coding=utf-8
#%matplotlib inline
import mxnet
from mxnet import autograd
import random
import matplotlib.pyplot as plt
from mxnet import ndarray as nd


#generate the dataset

# the dimension number is 2,characteristic number is 2
num_inputs = 2
# the number of training dataset is 1000
num_examples = 1000
# the true weight is 2 and -3.4 (2 dimensions)
true_w = [2, -3.4]
# the true bias is 4.2
true_b = 4.2
# Randomly generated training data X with mean of 0 and variance of 1,
# obeying normal distribution(正态分布)
features= nd.random_normal(shape=(num_examples, num_inputs))
# Generate corresponding output y according to X, w, B
labels = true_w[0] * features[:, 0] + true_w[1] * features[:, 1] + true_b
# Add random noise to y
labels += 0.01 * nd.random_normal(shape=labels.shape)


print(features[0], 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值