Scikit-learn 中的 train_test_split
函数是机器学习任务中常用的工具,用于将数据集分为训练集和测试集。以下是一些关于如何使用该函数的基础知识。
用途:
train_test_split
函数通常用于模型开发过程中的数据划分,以确保模型在未见过的数据上表现良好。参数:
X
: 特征数据。y
: 标签数据。test_size
: 测试集的比例,可以是分数或整数。random_state
: 随机种子,确保结果的可重复性。
示例:
from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
扩展阅读
想要了解更多关于 Scikit-learn 的信息,可以参考以下链接:
相关资源
Machine Learning