2019-05-29
阅读量:
530
机器学习划分数据集的好处
所有机器学习模型的一个重要方面是确定它们的准确性。现在,为了确定它们的准确性,可以使用给定的数据集训练模型,然后使用该模型预测同一数据集的响应值,从而找到模型的准确性。
但这种方法有几个缺陷,如:
- 目标是估计模型在样本外数据上的可能性能。
- 最大化训练准确性奖励过于复杂的模型,这些模型不一定会推广我们的模型。
- 不必要的复杂模型可能会过度拟合训练数据。
# load the iris dataset as an example
from sklearn.datasets import load_iris
iris = load_iris()
# store the feature matrix (X) and response vector (y)
X = iris.data
y = iris.target
# splitting X and y into training and testing sets
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=1)
# printing the shapes of the new X objects
print(X_train.shape)
print(X_test.shape)
# printing the shapes of the new y objects
print(y_train.shape)
print(y_test.shape)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论