GridSearchCV.grid_scores_和mean_validation_score报错
GridSearchCV.grid_scores_和mean_validation_score报错
0. 写在前面
参考书
《Python数据科学手册》
工具
python3.5.1,Jupyter Notebook
1. 问题描述和解决过程
在P438页,5.13.4 示例:不是很朴素的贝叶斯中的2. 使用自定义评估器小节中有这样一行代码
scores = [val.mean_validation_score for val in grid.grid_scores_]
运行之后报错:
AttributeError: 'GridSearchCV' object has no attribute 'grid_scores_'

经过百度了之后,可以知道grid_scores_在最新的sklearn中已经被弃用了,换成了cv_results_,参考链接:https://blog.csdn.net/weixin_40283816/article/details/83346098
那么,更改这个参数后,依然报错:
AttributeError: 'str' object has no attribute 'mean_validation_score'

这个问题就再也没有搜到好的解决方案了,所以我去查了GridSearchCV的文档:https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html
然后发现,关于cv_results_的内容如下:

这就很尴尬了,所以没有一个参数是包含validation关键字的,我的理解是,验证集和测试集在某种情况下可以认为是等价的。所以我猜测mean_validation_score对应的应该就是mean_test_score。
这样,原来的代码就改成了
scores = grid.cv_results_['mean_test_score']
为了证明我的猜想是正确的,所以,按照得到的scores结果,顺着其他的代码,知道最后绘图:

事实证明,跟书上得到图一毛一样,所以证明我对源代码修改的猜想是正确的。
即证明了:
旧版本代码:scores = [val.mean_validation_score for val in grid.grid_scores_]
与新版本代码:scores = grid.cv_results_['mean_test_score']
等价!
2. 不想比比直接看结果部分
将代码:scores = [val.mean_validation_score for val in grid.grid_scores_]
改成:scores = grid.cv_results_['mean_test_score']
我的CSDN:https://blog.csdn.net/qq_21579045
我的博客园:https://www.cnblogs.com/lyjun/
我的Github:https://github.com/TinyHandsome
纸上得来终觉浅,绝知此事要躬行~
欢迎大家过来OB~
by 李英俊小朋友
GridSearchCV.grid_scores_和mean_validation_score报错的更多相关文章
- Windows 7上执行Cake 报错原因是Powershell 版本问题
在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...
- 关于VS2015 ASP.NET MVC添加控制器的时候报错
调试环境:VS2015 数据库Mysql WIN10 在调试过程中出现类似下两图的同学们,注意啦. 其实也是在学习的过程中遇到这个问题的,找了很多资料都没有正面的解决添加控制器的时候报错的问题,还是 ...
- php报错 ----> Call to undefined function imagecreatetruecolor()
刚才在写验证码的时候,发现报错,然后排查分析了一下,原来是所用的php版本(PHP/5.3.13)没有开启此扩展功能. 进入php.ini 找到extension=php_gd2.dll ,将其前面的 ...
- scp报错 -bash: scp: command not found
环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...
- VS2015使用scanf报错的解决方案
1.在程序最前面加: #define _CRT_SECURE_NO_DEPRECATE 2.在程序最前面加: #pragma warning(disable:4996) 3.把scanf改为scanf ...
- VS项目中使用Nuget还原包后编译生产还一直报错?
Nuget官网下载Nuget项目包的命令地址:https://www.nuget.org/packages 今天就遇到一个比较奇葩的问题,折腾了很久终于搞定了: 问题是这样的:我的解决方案原本是好好的 ...
- Tomcat启动报错org.springframework.web.context.ContextLoaderListener类配置错误——SHH框架
SHH框架工程,Tomcat启动报错org.springframework.web.context.ContextLoaderListener类配置错误 1.查看配置文件web.xml中是否配置.or ...
- Android——eclipse下运行android项目报错 Conversion to Dalvik format failed with error 1解决
在eclipse中导入android项目,项目正常没有任何错误,但是运行时候会报错,(clean什么的都没用了.....)如图: 百度大神大多说是jdk的问题,解决: 右键项目-Properties如 ...
- 报错:You need to use a Theme.AppCompat theme (or descendant) with this activity.
学习 Activity 生命周期时希望通过 Dialog 主题测试 onPause() 和 onStop() 的区别,点击按钮跳转 Activity 时报错: E/AndroidRuntime: FA ...
随机推荐
- RK平台images打包细则【转】
本文转载自;https://blog.csdn.net/wangxueming/article/details/52808739 IMGs打包细节 平台: RK3288 背景: RK3288编译产生了 ...
- Spring Boot2.0之web开发
1.关于静态资源的访问 在我们开发Web应用的时候,需要引用大量的js.css.图片等静态资源. Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则: /s ...
- elasticsearch ——id字段说明,内部是_uid
_id field Each document indexed is associated with a _type (see the section called “Mapping Typesedi ...
- 在node.js中建立你的第一个HTTp服务器
这一章节我们将从初学者的角度介绍如何建立一个简单的node.js HTTP 服务器 创建myFirstHTTPServer.js //Lets require/import the HTTP modu ...
- PS 滤镜— — 镜头光晕
clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...
- ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)
Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...
- css 跳转电脑分辨率
因为我们经常在项目中要适配各种屏幕,为了方便前端的开发和测试.我们可以直接把电脑的分辨率调整到需要适配的最小的分辨率,其实还有一种更直接粗暴的方法.直接按F12打开控制台,在收拉浏览器就能看到目前的分 ...
- Digging-贪心
When it comes to the Maya Civilization, we can quickly remind of a term called the end of the world. ...
- JVM中的Hello World运行机制:
栗子: package zagoo; public class HelloWorld { public static String HELLOWORLD="Hello World" ...
- Word直接发表博客测试
这是我现在使用的VSCode! 这是另一段测试内容!