机器学习-Logistic回归之使用随机梯度上升算法预测病马死亡率
2017-01-24 23:32
651 查看
运行环境:ubuntu16.10+MATLAB2016a
数据集:
该数据集来自2010年1月11日的UCI机器学习数据库,该数据最早由加拿大安大略省圭尔夫大学计算机系Mary McLeish和Matt Cecile收集。每一行为一个样本,最后一列为标签。
可自行百度“从疝气病症预测病马的死亡率的数据集”
基于MATLAB的代码:
%%机器学习-logistic回归-使用随机梯度上升算法预测病马死亡率 %%machine learning-logistic regression-predict mortality using stochastic gradient ascent algorithm clear; trainSet = importdata('horseColicTraining.txt'); [m,n] = size(trainSet); trainVectors = zeros(m,n); trainVectors(:,1) = ones(m,1); trainVectors(:,2:end) = trainSet(:,1:end-1); trainLabels = trainSet(:,end); maxCycles = 500; %最大迭代次数 weights = ones(1,n); %回归系数 rightRate = zeros(1,10); for k = 1:10 for i = 1:maxCycles for j = 1:m alpha = 4.0 / (1.0+i+j) + 0.01; %步长是可变的 randIndex = fix(1+(m-1)*rand); h = 1.0./(1 + exp(-trainVectors(randIndex,:) * weights')); error = trainLabels(randIndex) - h; weights = weights + alpha * error *trainVectors(randIndex,:); end end %%测试 testSet = importdata('horseColicTest.txt'); [m,n] = size(testSet); testVectors = zeros(m,n); testVectors(:,1) = ones(m,1); testVectors(:,2:end) = testSet(:,1:end-1); testLabels = testSet(:,end); prob = 1.0./(1 + exp(-testVectors * weights')); predictLabels = prob>0.5; rightRate(k) = sum(predictLabels == testLabels) / m; end bar(1:10,rightRate); xlabel('实验次数'); ylabel('正确率');
实验结果:
这是进行了10次实验统计出来的识别正确率,使用MATLAB的mean函数计算十次正确率的平均值,一般在0.65左右。
相关文章推荐
- Logistic 回归(sigmoid函数,手机的评价,梯度上升,批处理梯度,随机梯度,从疝气病症预测病马的死亡率
- 机器学习之logistic回归的梯度上升算法
- logistic回归算法学习笔记-从疝气症预测病马死亡率
- 机器学习-Logistic回归之梯度上升法
- 机器学习逻辑回归:使用C++语言手工编写程序对a1a数据集进行Logistic分类
- 逻辑斯特回归(随机梯度上升算法)预测马疝病的死亡率问题
- Python语言描述机器学习之Logistic回归算法
- 机器学习实战------利用logistics回归预测病马死亡率
- 机器学习之一:logistic回归分析(含Matlab代码)
- 机器学习实战 - 读书笔记(11) - 使用Apriori算法进行关联分析
- 机器学习实战_08预测数值型数据-回归
- 机器学习实战——使用K-近邻算法进行约会配对
- 机器学习之logistic回归的梯度上升算法
- 机器学习之Logistic回归(逻辑蒂斯回归)
- 【机器学习实战三:Logistic回归之点的二分类和预测病马的死亡率】
- [置顶] Python3《机器学习实战》学习笔记(六):Logistic回归基础篇之梯度上升算法
- 机器学习实战学习笔记(四):Logistic回归
- 机器学习-学习笔记2-监督学习中回归方程的建立以及预测
- 机器学习:以二元决策树为基学习器实现梯度提升算法的回归分析
- Logistic回归---从疝气病症预测马的死亡率