Softmax回归
来源:互联网 发布:软件著作权评估方法 编辑:程序博客网 时间:2024/06/15 16:22
Softmax回归是Logistic回归的多分类推广。
对于
当给定一个样本
当
同Logistic回归计算方法,得到随机梯度:
代码实现
def soft_max(data, k, alpha, lamda): n = len(data[0]) - 1 #样本维度 w = np.zeros((k, n)) #权值初始化 wNew = np.zeros((k, n)) #临时权值 for times in range(1000): for d in date: x = d[:-1] # 输入向量 for k in range(k): # k类别 y = 0 #期望输出标量 if int(d[-1] + 0.5) == k: y = 1 p = predict(w, x, k) g = (y - p)*x #梯度 n维列向量 wNew[k] = w[k] + (alpha * g + lamda * w[k]) w = wNew.copy() return w
附录
import numpy as npimport matplotlib.pyplot as pltfig = plt.figure()plt.figure(figsize=(1, 1))u = np.linspace(0,4,500)x,y = np.meshgrid(u,u)ax1 = fig.add_subplot(1,2,1) # softmaxz = np.log(np.exp(x) + np.exp(y))ax1.contour(x,y,z,20)ax2 = fig.add_subplot(1,2,2) # maxz = [0 for i in range(len(u))]for i in range(len(u)): z[i] = [0 for k in range(len(u))] for j in range(len(u)): z[i][j] = max(x[i][j] ,y[i][j])ax2.contour(x,y,z,20)plt.show()
阅读全文
0 0
- softmax回归(Softmax Regression)
- Softmax回归
- softmax 回归
- softmax回归
- Softmax回归
- Softmax回归
- Softmax回归
- Softmax回归
- softmax回归
- Softmax回归
- Softmax回归
- softmax回归
- Softmax回归
- softmax回归
- softmax回归
- softmax回归
- Softmax回归
- softmax回归
- Eclipse中的操作技巧
- Django教程之五-----编写你的第一个Django应用(3)
- 百度策略笔试题
- 【Linux】SYSFS虚拟文件系统
- React Native 时间转换格式工具类
- Softmax回归
- 02 css的学习笔记
- java.lang.NoClassDefFoundError问题的解决
- Leetcode 312. Burst Balloons
- 实体类中序列化类对象属性Parcelable
- MySQL数据切分、负载均衡和集群
- java经典面试题(4)
- c++函数的传值方式
- 记录Hbuilder项目使用xcode离线打包上传苹果商店踩过的坑