matlab(5) : 求得θ值后用模型来预测 / 计算模型的精度
求得θ值后用模型来预测 / 计算模型的精度
ex2.m部分程序
%% ============== Part 4: Predict and Accuracies ==============
% After learning the parameters, you'll like to use it to predict the outcomes
% on unseen data. In this part, you will use the logistic regression model
% to predict the probability that a student with score 45 on exam 1 and
% score 85 on exam 2 will be admitted.
%
% Furthermore, you will compute the training and test set accuracies of
% our model.
%
% Your task is to complete the code in predict.m
% Predict probability for a student with score 45 on exam 1
% and score 85 on exam 2
prob = sigmoid([1 45 85] * theta);
fprintf(['For a student with scores 45 and 85, we predict an admission ' ...
'probability of %f\n\n'], prob);
% Compute accuracy on our training set
p = predict(theta, X);
fprintf('Train Accuracy: %f\n', mean(double(p == y)) * 100); %若p==y,则返回1否则返回0;然后对这些0,1求平均值
fprintf('\nProgram paused. Press enter to continue.\n');
pause;
predict.m
function p = predict(theta, X)
%PREDICT Predict whether the label is 0 or 1 using learned logistic
%regression parameters theta
% p = PREDICT(theta, X) computes the predictions for X using a
% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)
m = size(X, 1); % Number of training examples
% You need to return the following variables correctly
p = zeros(m, 1);
% ====================== YOUR CODE HERE ======================
% Instructions: Complete the following code to make predictions using
% your learned logistic regression parameters.
% You should set p to a vector of 0's and 1's
%
for i=1:m
if sigmoid(X(i,:) * theta) >=0.5
p(i) = 1;
else
p(i) = 0;
end
end
% =========================================================================
end
matlab(5) : 求得θ值后用模型来预测 / 计算模型的精度的更多相关文章
- 性能测试学习之二 ——性能测试模型(PV计算模型)
PV计算模型 现有的PV计算公式是: 每台服务器每秒平均PV量 =( (总PV*80%)/(24*60*60*40%))/服务器数量 =2*(总PV)/* (24*60*60) /服务器数量 通过定积 ...
- 第二步:将LAD结果的属性值二(多)值化,投入计算模型
一文详解LDA主题模型 - 达观数据 - SegmentFault 思否 https://segmentfault.com/a/1190000012215533 SELECT COUNT(1) FRO ...
- matlab(8) Regularized logistic regression : 不同的λ(0,1,10,100)值对regularization的影响,对应不同的decision boundary\ 预测新的值和计算模型的精度predict.m
不同的λ(0,1,10,100)值对regularization的影响\ 预测新的值和计算模型的精度 %% ============= Part 2: Regularization and Accur ...
- 基于MATLAB的中值滤波均值滤波以及高斯滤波的实现
基于MATLAB的中值滤波均值滤波以及高斯滤波的实现 作者:lee神 1. 背景知识 中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值. 中值滤 ...
- [引用]MATLAB中的fft后为何要用fftshift
原文地址:MATLAB中的fft后为何要用fftshift fft是一维傅里叶变换,即将时域信号转换为频域. fftshift是针对频域的,将FFT的DC分量移到频谱中心,重新排列fft,fft1和… ...
- YII2 用 in查询的时候出现无结果, 删除某些值后查询有结果 提前sort数组即可
YII2 用 in查询的时候出现无结果, 删除某些值后查询有结果, 在数组前用了一个 array_merge 合并了2个数组. 排查发现是 数组中键值没有挨着从0开始 另外没有从小到大, 没观察室哪个 ...
- 使用matlab批量处理图像后在指定文件夹存储
使用matlab批量处理图像后在指定文件夹存储 clear;clc;close all; Files=dir('D:\文件及下载相关\文档\MATLAB\postgraduate\Kodak\*.jp ...
- 从信用卡欺诈模型看不平衡数据分类(1)数据层面:使用过采样是主流,过采样通常使用smote,或者少数使用数据复制。过采样后模型选择RF、xgboost、神经网络能够取得非常不错的效果。(2)模型层面:使用模型集成,样本不做处理,将各个模型进行特征选择、参数调优后进行集成,通常也能够取得不错的结果。(3)其他方法:偶尔可以使用异常检测技术,IF为主
总结:不平衡数据的分类,(1)数据层面:使用过采样是主流,过采样通常使用smote,或者少数使用数据复制.过采样后模型选择RF.xgboost.神经网络能够取得非常不错的效果.(2)模型层面:使用模型 ...
- VUE项目中使用this.$forceUpdate();解决页面v-for中修改item属性值后页面v-if不改变的问题
VUE项目中使用this.$forceUpdate();解决页面v-for中修改item属性值后页面v-if不改变的问题:https://blog.csdn.net/jerrica/article/d ...
随机推荐
- Extjs GridField 总结
此代码为完整代码,其中包含定位.使用 Enter 键,来实现 Tab 键. Ext.define('xxx.recordBook.view.EditGrid', { extend: 'Ext.form ...
- Appium移动自动化测试-----(十二)appium API 之 TouchAction 操作
Appium的辅助类,主要针对手势操作,比如滑动.长按.拖动等. 1.按压控件 方法: press() 开始按压一个元素或坐标点(x,y).通过手指按压手机屏幕的某个位置. press(WebElem ...
- stl 自定义排序与删除重复元素
转: STL—vector删除重复元素 STL提供了很多实用的算法,这里主要讲解sort和unique算法. 删除重复元素,首先将vector排序. sort( vecSrc.begin(), vec ...
- 好用的idea插件
[Alibaba Java Coding Guidelines alibaba]阿里巴巴 代码规约扫描插件. [jRebel]可以热部署Java项目而不用重启. [http://139.199.89. ...
- java jri null
java通过jri调用r文件,r文件必须和当前类在同一目录下,然后才能re.eval("source(fpath)")执行脚本;其中fpath为通过re.assign设置的文件全路 ...
- PAT甲级 Dijkstra 相关题_C++题解
Dijkstra PAT (Advanced Level) Practice Dijkstra 相关题 目录 <算法笔记>重点摘要 1003 Emergency (25) <算法笔记 ...
- django使用pyecharts(1)----django加入echarts
Django 中使用 pyecharts.一.普通django加入echarts Django 模板渲染 Step 0: 新建一个 Django 项目 $ django-admin startproj ...
- Luogu5400 CTS2019随机立方体(容斥原理)
考虑容斥,计算至少有k个极大数的概率.不妨设这k个数对应的格子依次为(k,k,k)……(1,1,1).那么某一维坐标<=k的格子会对这些格子是否会成为极大数产生影响.先将这样的所有格子和一个数集 ...
- manacher 算法(最长回文串)
manacher算法: 定义数组p[i]表示以i为中心的(包含i这个字符)回文串半径长 将字符串s从前扫到后for(int i=0;i<strlen(s);++i)来计算p[i],则最大的p[i ...
- Python通用爬虫,聚焦爬虫概念理解
通用爬虫:百度.360.搜狐.谷歌.必应....... 原理: (1)抓取网页 (2)采集数据 (3)数据处理 (4)提供检索服务 百度爬虫:Baiduspider 通用爬虫如何抓取新网站? (1)主 ...