1 Star 0 Fork 0

jessssy_yang/Deep-Learning-in-Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Gradient_Descent.py 883 Bytes
一键复制 编辑 原始数据 按行查看 历史
from sklearn.metrics import mean_squared_error
import numpy as np
import matplotlib.pyplot as plt
def pred(input_data, target, weights):
return ((input_data * weights).sum())
def get_slope(input_data, target, weights):
preds = pred(input_data, target, weights)
error = target - preds
slope = 2 * input_data * error
return slope
def get_mse(input_data, target, weights):
preds = pred(input_data, target, weights)
return mean_squared_error([preds], [target])
weights = np.array([0, 2, 1])
input_data = np.array([1, 2, 3])
target = 0
n_updates = 20
mse_hist = []
for i in range(n_updates):
slope = get_slope(input_data, target, weights)
weights = weights + (learning_rate * slope)
mse = get_mse(input_data, target, weights)
mse_hist.append(mse)
plt.plot(mse_hist)
plt.xlabel('Iterations')
plt.ylabel('Mean Squared Error')
plt.show()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jessssy_yang/Deep-Learning-in-Python.git
git@gitee.com:jessssy_yang/Deep-Learning-in-Python.git
jessssy_yang
Deep-Learning-in-Python
Deep-Learning-in-Python
master

搜索帮助