机器学习预测结果评价的score方法取值分类及决定系数R^2(Coefficient of Determination)的原理及推导

机器学习中准确率、精确率、召回率、误报率、漏报率、F1-Score、AP&mAP、AUC、MAE、MAPE、MSE、RMSE、R-Squared等指标的定义和说明 在机器学习和深度学习用于异常检测(Anomaly detection)、电子商务(E-commerce)、信息检索(Information retrieval, IR)等领域任务(Task)中,有很多的指标来判断机器学习和深度学习效果的好坏。这些指标有相互权衡的,有相互背向的,所以往往需要根据实际的任务和场景来选择衡量指标。本篇博文对这些指标进行一个梳理。 阅读详情

score方法的取值分类

Python机器学习sklearn里的score()方法,主要用于度量给定测试集的预测效果的好坏。

当y为连续变量时,score的取值为R2;当y为分类变量时,score的取值为准确率accuracy。

其中:

R2 =(1-u/v),
u=((y_true - y_pred) ** 2).sum(),
v=((y_true - y_true.mean()) ** 2).sum();

accuracy=分类算法正确的分类数/总分类数。

决定系数R2(Coefficient of Determination)的性质

决定系数(记为R2或r2),亦称测定系数、可决系数、可决指数。与复相关系数类似的,在统计学中用于度量因变量的变异中可由自变量解释部分所占的比例,以此来判断统计模型的解释力。

对于简单线性回归而言,判定系数为样本简单相关系数(记为R或r)的平方(简单相关系数又称皮尔逊相关系数或者线性相关系数)。当加入其他回归自变量后,决定系数相应地变为多重相关系数的平方。

R2的公式

R2 =(1-u/v),
u=((y_true - y_pred) ** 2).sum(),
v=((y_true - y_true.mean()) ** 2).sum()
或者:
R2=SSE/SST=1-SSR/SST

R2的原理

首先说明一下几个参数的定义:

离差

一个特定数值对于其平均值的偏离

变异

一变量的各数值对于其平均值的偏离,称为变异。通常用离差平方和来描述变异程度。

离差平方和

离差平方和又简称平方和(Sum of square)。

均方(Mean square)

平方和被相应的自由度去除,得到平均平方,简称为均方(Mean square)。

样本标准差

样本标准差就是被自由度(n-1)所平均x对于x‾\overline{x}x的离差均方的算术平方根。

score函数 机器学习_机器学习系列18:核函数 机器学习系列18:核函数让我们来考虑这样一个问题,现在给定一个数据集,让你划分出决策边界,该怎么办呢?数据集中正样本为「叉」,负样本为「圈」,如下图:第一反应就是用一个高阶多项式去构造一个假设函数,当假设函数大于等于零时,我们就可以认为它为正样本,否则为负样本,类似下面这种形式:但是有一个问题出现了,我们不能确定构造的假设函数就是最符合这个例子的高阶多项式,可能还有其他的高阶多项式能够更好地符合这... 阅读详情

相关推荐

[已解决] 决定系数R2为何为负 from sklearn.metrics import r2_score

决定系数R2为何为负 from sklearn.metrics import r2_score

Next_SummerAgain的博客 2万+

车辆属性多目标预测在定价与能效评估中的应用

本文解析了Kaggle车辆属性预测竞赛,该赛题要求根据技术参数预测燃油经济性和市场价格,属于典型的多目标回归问题。数据集包含车辆制造信息、规格参数等结构化数据,规模适中(5.7MB),适合练习完整的数据科学流程。竞赛采用R²作为评估指标,考察模型对目标变量方差的解释能力。文中对比了六种解决方案:从简单的启发式规则到线性回归、树模型、神经网络及集成方法,分析了各方法的适配度、优缺点及实现要点。特别指出树模型(如XGBoost)在结构化数据中的优势,以及多任务学习对相关目标预测的潜在提升。该案例对汽车定价、能效

Mr数据杨 554

QComboBox设置最大显示数量多余的用滑动条,以及QComboBox::setMaxVisibleItems()不起作用的问题

QComoboBox是Qt封装的一个选择框的东西,但是我在使用过程中有一点感觉很不好,如图: 不论你往里面添加多少个它都会给你显示全部,甚至给你铺满全屏,后来看了官方文档发现有个setMaxVisibleItems()的方法,我欣喜若狂啊,终于特么的能解决了,但是,很遗憾,不知为啥,我设置上之后并没有起作用,依然会显示全部,后来搜了百度发现有个人是这样解决的 QComboBox *box = ne...

Aboveground的博客 4924

主动式桥梁防船撞预警系统的方案汇总

本系统以精密光电测高前端(2台,上下游各1台)、固态雷达(2台,上下游各1台)、AIS(1台)、偏航辅助前端(4台,上下游各2台)为核心,通过人工智能,对画面上的船舶目标进行深度学习、精确定位,再用系统集成方法将各设备有机结合在一起,构建成套的桥梁防撞主动预警系统,全天候监控过往船舶。主动式桥梁防船撞预警系统主要船舶监测采集单元、控制单元、船舶超高、偏航信息检测单元、以及视频监控单元组成,,通过声光警示、短信文字、船舶身份识别及海事对讲频道、视频录像取证等多种手段与船舶进行信息互动,主动防止船舶碰撞桥梁!

gdxixun的博客 988

Python Selenium调用IE11报错全解析:从环境配置到稳定运行

在Web自动化测试领域,Selenium作为主流的跨浏览器测试框架,其核心原理是通过WebDriver协议与不同浏览器的驱动程序进行通信,实现对浏览器行为的模拟与控制。这一技术为软件测试的自动化、回归测试的效率提升提供了重要价值,广泛应用于金融、政务等对遗留系统兼容性要求高的行业场景。然而,当技术栈涉及过时的浏览器如IE11时,环境配置的复杂性显著增加,特别是Python与Selenium的组合常遭遇驱动兼容性、安全设置等挑战。本文聚焦于解决Python Selenium驱动IE11时的典型报错问题,深入剖

weixin_28834765的博客 327

osgEarth实战:5分钟搞定3DTiles模型加载(附完整配置代码)

本文提供了一份osgEarth加载3DTiles模型的实战指南。通过详解核心Earth文件配置与精简的C++集成代码,帮助开发者快速在三维地球场景中集成倾斜摄影与BIM等海量模型,并分享了性能调优与常见问题排查技巧,有效提升开发效率。

jjj34的博客 483

基于强化学习控制策略的三相逆变器仿真

强化学习控制器的核心在于定义状态空间、动作空间、奖励函数以及选择合适的强化学习算法(例如DQN、DDPG等)。对于三相逆变器,状态可以是输出电压、电流等信息;动作则可能是调制指数的变化量;奖励函数则应鼓励快速准确地跟踪参考信号。定义状态空间和动作空间状态空间可以包括逆变器的输出电压、电流及其变化率等信息。动作空间则是控制器可执行的动作,例如PWM信号的调整幅度。matlab深色版本% 定义状态和动作空间维度numObs = 6;% 假设有六个状态变量(例如三相电压和电流)

amy_mhd的博客 143

【RT-DETR有效改进】为什么YOLO版本的RT-DETR训练模型不收敛精度差的问题

本文的内容同样为本专栏的前期预热文章,文章主要解释一下为什么有的人跑ultralytics仓库的RT-DETR精度很差,模型不收敛,mAP异常的情况。为了验证这一情况我也是跑了多个实验,从多个数据集出发,100-500的数据集我跑了大概5个数据集,1000的我跑了二个,2000的我跑了一个,4000的跑了一个,同时其中一些版本我也用了不同的batch_size来出发验证精度异常的情况。

Snu77的博客 9767

杰理外挂flash使用教程(三): 打包提示音到外部flash(2)

本教程详细介绍了提示音制作与程序配置的全流程规范。提示音制作要求包括:英文命名(8字符内)、单声道转换、标准目录结构(cpu/br23/tools/)及使用user_tone_g.bat脚本生成res.bin资源文件。程序配置需修改:1)启用NOR_FS文件系统;2)调整存储空间;3)配置外置Flash参数;4)增强下载脚本追加资源参数。测试阶段建议替换开机提示音验证功能,扩展开发可参考tone_player.c的索引播放逻辑。所有操作均配有图示说明,关键配置需修改对应头文件和脚本参数。

qq_42014563的博客 593

基于LSTM算法实现交通流量预测(Pytorch版)

本研究采用PyTorch框架,设计并实现了一种基于LSTM(Long Short-Term Memory)网络的交通流量预测模型。针对时序性显著的交通流量数据,模型首先将多节点、多通道的时空信息整合为一维特征输入至多层LSTM单元,利用其捕捉长期依赖及短期波动的能力进行深度学习。全连接层随后调整时间步长以适应预测周期需求。模型结构灵活,能适应不同节点数、输入输出长度及通道配置,实现在给定历史流量数据基础上对未来交通流量的精准预测,为交通管理与规划提供数据驱动支持。

打酱油的葫芦娃 4642

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 将python机器学习sklearn工具包中的datasets数据探索
下一篇: scikit-learn算法分类、模块、建模流程及设计原则
Zen of Data Analysis
博客等级 码龄12年 120粉丝 102原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址