机器学习 1.回归
来源:互联网 发布:adc0804连单片机 编辑:程序博客网 时间:2024/06/06 01:26
线性回归:
1.目标函数增加L2正则
θ存在解析式:
使用梯度下降进行解θ:=>
代码:
import numpy as npdef regression(data, alpha, lamda): n=len(data[0])-1 theta=np.zeros(n) for i in range(30): for d in data: y_hat=np.dot(d[:-1],theta) y_loss=y_hat-d[-1:] theta=theta-alpha*y_loss*d[:-1]+lamda*theta print(i,theta)data=[[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7]]regression(data,0.01,0.1)
Logistic回归:二分类
1.Logistic/sigmoid函数:=>
代码:
import scipy as spimport numpy as npfrom sklearn.model_selection import train_test_splitfrom sklearn import metricsfrom sklearn.linear_model import LogisticRegressionx = np.loadtxt("wine.data", delimiter=",", usecols=(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)) # 获取属性集y = np.loadtxt("wine.data", delimiter=",", usecols=(0)) # 获取标签集print(x) # 查看样本# 加载数据集,切分数据集80%训练,20%测试x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) # 切分数据集# 调用逻辑斯特回归model = LogisticRegression()model.fit(x_train, y_train)print(model) # 输出模型# make predictionsexpected = y_test # 测试样本的期望输出predicted = model.predict(x_test) # 测试样本预测# 输出结果print(metrics.classification_report(expected, predicted)) # 输出结果,精确度、召回率、f-1分数print(metrics.confusion_matrix(expected, predicted)) # 混淆矩阵
softmax回归:多分类
概率:
似然函数(似然函数是一种关于统计模型参数的函数。给定输出x时,关于参数θ的似然函数L(θ|x)(在数值上)等于给定参数θ后变量X的概率:L(θ|x)=P(X=x|θ)):
对数似然:
梯度:=>
代码:
0 0
- 机器学习 1.回归
- Stanford机器学习笔记-1.线性回归
- 机器学习-线性回归
- 机器学习-Logistic回归
- 【机器学习】线性回归
- 机器学习-线性回归
- 机器学习-logistic回归
- 机器学习 线性回归
- 【机器学习】Logistic回归
- 机器学习-线性回归
- 机器学习-逻辑回归
- 机器学习--线性回归
- 机器学习-Logistic回归
- 机器学习:逻辑回归
- 机器学习 回归notes
- 机器学习---逻辑回归
- 机器学习之回归
- 机器学习-Logistic回归
- 数据结构之二叉树
- BZOJ 2820 YY的GCD
- MySQL的读写分离之Amoeba
- ubuntu 下 anaconda 安装插件
- Ubuntu安装oh-my-zsh
- 机器学习 1.回归
- 无等待地从一个消息队列中取得消息, OSQAccept()
- 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
- UI设计原则 Material Design
- 卡拉兹(Callatz)猜想
- 浅谈Java内部类的四个应用场景
- android 阴影效果
- 把本地项目提交到 github 上
- Js bug 小结