Scikit-Learn
python中数据集划分函数StratifiedShuffleSplit的使用
原文:https://blog.csdn.net/m0_38061927/article/details/76180541
交叉验证(Cross-Validation)是指在给定的建模样本中,拿出其中的大部分样本进行模型训练,生成模型,留小部分样本用刚建立的模型进行预测,并求这小部分样本的预测误差,记录它们的平方加和。这个过程一直进行,直到所有的样本都被预测了一次而且仅被预测一次,比较每组的预测误差,选取误差最小的那一组作为训练模型。
用法:
from sklearn.model_selection import StratifiedShuffleSplit
StratifiedShuffleSplit(n_splits=10,test_size=None,train_size=None, random_state=None)
Parameters:
n_splits:将训练数据分成train/test对的组数,可根据需要进行设置,默认为10
test_size,train_size:设置train/test对中train和test所占的比例
random_state:将样本随机打乱
sklearn.preprocessing模块
http://scikit-learn.org/stable/modules/preprocessing.html#preprocessing
Standardization
The preprocessing module further provides a utility class StandardScaler that implements the Transformer API to compute the mean and standard deviation on a training set so as to be able to later reapply the same transformation on the testing set.
preprocessing模块还提供了一个实用类StandardScaler,这个类实现了一个叫做Transformer的应用程序接口,能够计算训练数据的均值和标准差,从而在训练数据集上再次使用。
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X)
scaler.transform(X)