from sklearn.model_selection import cross_val_score
from sklearn.datasets import make_blobs
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.tree import DecisionTreeClassifier
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sklearn.preprocessing as preprocessing
from sklearn import preprocessing
from sklearn.linear_model import LinearRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
dataset_x,dataset_y=return_data.return_traindata()
X_train, X_test, y_train, y_test = train_test_split(dataset_X, dataset_Y,
test_size=0.2,
random_state=42)
alphas=[10,15,20,25,30]
test_sores=[]
for alpha in alphas:
clf = ExtraTreesClassifier(n_estimators=alpha, max_depth=None,
min_samples_split=3, random_state=1)
sore=cross_val_score(clf,X_train,
y_train.ravel(),cv=5,
scoring='accuracy') #交叉验证
test_sores.append(np.mean(sore))
print("testing",str(alpha))
print(test_sores)
plt.figure()
plt.plot(alphas,test_sores, color='blue')
plt.scatter(alphas,test_sores,s=75,c="red",alpha=0.5)
plt.show()
sklearn交叉验证(acc)
最新推荐文章于 2023-09-15 09:33:51 发布