import pandas as pd
from sklearn.datasets import load_iris
from sklearn.svm import SVC
#import data
iris = load_iris()
X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = iris.target
#split data
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, shuffle=False)
#modeling using SVM
model = SVC(kernel='linear', C = 1)
model.fit(X_train, y_train)
model.score(X_test, y_test)
# here I get score: 0.8666666
# Now I use cross_validation with cv = 5,
from sklearn.model_selection import cross_val_score
model = SVC(kernel='linear', C = 1)
scores = cross_val_score(model, X, y, cv = 5, scoring = "accuracy")
scores
#here I got array([0.96666667, 1. , 0.96666667, 0.96666667, 1. ])
上述数组中没有一个数字等于 0.866666,我想知道为什么会发生不一致(因为“cv = 5”与条件“test_size = 0.2”匹配)。