from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score
# 加载数据集 iris = load_iris() X = iris.data y = iris.target
from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split, cross_val_score from sklearn.ensemble import RandomForestClassifier
# 加载数据集 iris = load_iris() X, y = iris.data, iris.target
# 创建模型 model = RandomForestClassifier(n_estimators=100)
# 进行k折交叉验证 scores = cross_val_score(model, X, y, cv=5) # 使用5折交叉验证
from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier from sklearn.svm import SVC from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score
# 加载数据集 iris = load_iris() X, y = iris.data, iris.target X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)