sklearn学习3----模型选择和评估(1)训练集和测试集的切分
来自链接:https://blog.csdn.net/zahuopuboss/article/details/54948181
1、sklearn.model_selection.train_test_split随机划分训练集和测试集
官网文档:http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html#sklearn.model_selection.train_test_split
- 一般形式:
train_test_split是交叉验证中常用的函数,功能是从样本中随机的按比例选取train data和testdata,形式为:
- from sklearn.model_selection.train_test_split
- X_train,X_test, y_train, y_test =
- cross_validation.train_test_split(train_data,train_target,test_size=0.4, random_state=0)
- 参数解释:
train_data:所要划分的样本特征集
train_target:所要划分的样本结果
test_size:样本占比,如果是整数的话就是样本的数量
random_state:是随机数的种子。
随机数种子:其实就是该组随机数的编号,在需要重复试验的时候,保证得到一组一样的随机数。比如你每次都填1,其他参数一样的情况下你得到的随机数组是一样的。但填0或不填,每次都会不一样。
随机数的产生取决于种子,随机数和种子之间的关系遵从以下两个规则:
种子不同,产生不同的随机数;种子相同,即使实例不同也产生相同的随机数。
- 示例
- fromsklearn.cross_validation import train_test_split
- train= loan_data.iloc[0: 55596, :]
- test= loan_data.iloc[55596:, :]
- # 避免过拟合,采用交叉验证,验证集占训练集20%,固定随机种子(random_state)
- train_X,test_X, train_y, test_y = train_test_split(train,
- target,
- test_size = 0.2,
- random_state = 0)
- train_y= train_y['label']
- test_y= test_y['label']
sklearn学习3----模型选择和评估(1)训练集和测试集的切分的更多相关文章
- sklearn获得某个参数的不同取值在训练集和测试集上的表现的曲线刻画
from sklearn.svm import SVC from sklearn.datasets import make_classification import numpy as np X,y ...
- sklearn——train_test_split 随机划分训练集和测试集
sklearn——train_test_split 随机划分训练集和测试集 sklearn.model_selection.train_test_split随机划分训练集和测试集 官网文档:http: ...
- sklearn中的train_test_split (随机划分训练集和测试集)
官方文档:http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html ...
- 斯坦福大学公开课机器学习:advice for applying machine learning | model selection and training/validation/test sets(模型选择以及训练集、交叉验证集和测试集的概念)
怎样选用正确的特征构造学习算法或者如何选择学习算法中的正则化参数lambda?这些问题我们称之为模型选择问题. 在对于这一问题的讨论中,我们不仅将数据分为:训练集和测试集,而是将数据分为三个数据组:也 ...
- sklearn 模型选择和评估
一.模型验证方法如下: 通过交叉验证得分:model_sleection.cross_val_score(estimator,X) 对每个输入数据点产生交叉验证估计:model_selection.c ...
- sklearn学习总结(超全面)
https://blog.csdn.net/fuqiuai/article/details/79495865 前言sklearn想必不用我多介绍了,一句话,她是机器学习领域中最知名的python模块之 ...
- sklearn学习 第一篇:knn分类
K临近分类是一种监督式的分类方法,首先根据已标记的数据对模型进行训练,然后根据模型对新的数据点进行预测,预测新数据点的标签(label),也就是该数据所属的分类. 一,kNN算法的逻辑 kNN算法的核 ...
- Spark2.0机器学习系列之2:基于Pipeline、交叉验证、ParamMap的模型选择和超参数调优
Spark中的CrossValidation Spark中采用是k折交叉验证 (k-fold cross validation).举个例子,例如10折交叉验证(10-fold cross valida ...
- 机器学习之使用sklearn构造决策树模型
一.任务基础 导入所需要的库 import matplotlib.pyplot as plt import pandas as pd %matplotlib inline 加载sklearn内置数据集 ...
随机推荐
- kernel相关前沿技术了解
Intel MPX https://en.wikipedia.org/wiki/Intel_MPX SPDK http://aidaiz.com/spdk/ TCMalloc http://goog- ...
- [SPOJ1716] GSS3 - Can you answer these queries III
线段树操作. 维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可. 最后不知道怎么搞,query的时候返回了个结构体. #include <cstdio> #include ...
- 01.Python基础-1.Python简介及基础
python简介 python简介 python是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum(吉多·范罗苏姆)于1989年发明,第一个公开发行版发行于1991年. ...
- Problem 14
Problem 14 # Problem_14.py """ The following iterative sequence is defined for the se ...
- Windows常用软件
目录 Uninstall Tool FACapture Unlocker Uninstall Tool Uninstall Tool 这是一款可以彻底删除应用的软件,能连通注册表内容一起删除. FAC ...
- java并发之阻塞队列
在前面我们接触的队列都是非阻塞队列,比如PriorityQueue.LinkedList(LinkedList是双向链表,它实现了Dequeue接口). 阻塞队列与普通队列的区别在于:当队列是空的时, ...
- js sort根据数值大小自动排序(转)
var arrDemo = new Array(); arrDemo[0] = 10; arrDemo[1] = 50; arrDemo[2] = 51; arrDemo[3] = 100; arrD ...
- HDU 2035 不忍直视的水
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; in ...
- 上机题目(中级)- 两个超级大的整数相加相减 (Java)
代码例如以下: public class AddSub { public static void main(String[] args) { String a="46328648326846 ...
- MFC exe使用C++ dll中的std::string 崩溃
VC6中 MFC exe中 new 纯C++ dll dll 崩溃 我把纯C++的 dll,用/MTd 换成/MDd.就能够了