当前位置:网站首页>网格搜索法
网格搜索法
2022-06-21 06:17:00 【每天一道题】
意义
通过网格搜索法,可以确定超参数的值。
过程
首先先导入数据:
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import GridSearchCV
digits = datasets.load_digits()
X = digits.data
y = digits.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 666)
然后确定参数的值:
param_grid = [
{
'weights': ['uniform'],
'n_neighbors': [i for i in range(1, 11)]
},
{
'weights': ['distance'],
'n_neighbors': [i for i in range(1, 11)],
'p': [i for i in range(1, 6)]
}
]
最后即可训练数据:
grid_search = GridSearchCV(knn_clf, param_grid)
grid_search.fit(X_train, y_train)
显示最佳分类器的参数:
grid_search.best_estimator_
显示运用此分类器的准确度:
grid_search.best_score_
显示我们最开始创建的param_grid中的最佳参数:
grid_search.best_params_
提升刚刚训练数据的速度:
grid_search = GridSearchCV(knn_clf, param_grid, n_jobs = -1, verbose = 2)
grid_search.fit(X_train, y_train)
引入了n_jobs,后面的数字即为计算机的核,当取-1时即所有核都进行此次运算。而后面的verbose是为了显示这个过程中的一些细节。
边栏推荐
- leetcode 675. Cutting down trees for golf competitions - (day29)
- 深度理解RNN的梯度消失和LSTM为什么能解决梯度消失
- 认知语言学之框架与脚本
- 520泡泡的源码
- How to limit intranet speed
- Aurora8b10b IP use-04-ip routine application example
- 第一章:数据库系统概述(数据库期末复习)
- FPGA - 7 Series FPGA selectio -06- odelay of logic resources
- 模块 14 - 15:网络应用通信考试
- 递归建立链式二叉树,完成前中后序遍历以及其他功能(附源码)
猜你喜欢

MSF intranet penetration

C语言实现模拟银行存取款管理系统课程设计(纯C语言版)

FPGA - 7系列 FPGA SelectIO -04- 逻辑资源之IDELAY和IDELAYCTRL

Does intelligence need a body

正则表达式基础

Digital signal processing-07-dds IP application example

leetcode数据库mysql题目(难度:简单)

认知语言学之框架与脚本

Aurora8b10b IP usage-03-ip configuration application guide

Memorizing Normality to Detect Anomaly: Memory-augmented Deep Autoencoder for Unsupervised Anomaly D
随机推荐
Pychart sets the default interpreter for the project
User defined thread pool
双调查找:数组先递增后递减
WordPress pseudo original tool - update website one click pseudo original publishing software
Regular expression Basics
第6期:大学生应该选择哪种主流编程语言
Improved Object Categorization and Detection Using Comparative Object Similarity
Why should I use the source code of nametuple replace(‘,‘, ‘ ‘). Split() instead of split(‘,‘)
FPGA - 7系列 FPGA SelectIO -02- 源语简介
FPGA - 7 Series FPGA selectio -04- ideay and ideayctrl of logical resources
docker 安装mysql
[data mining] final review Chapter 3
Idea usage record
FPGA - 7 Series FPGA selectio -01- introduction and DCI technology introduction
How to limit intranet speed
Only your actions are the answers to these questions
xshell7远程连接服务器,挂起进程一直维持程序的运行
【利用MSF工具内网复现MS08-067】
tf. compat. v1.MetaGraphDef
Contos7 installing SVN server