整合學習demo(3) oob_bagging

doublejie1001發表於2020-11-05

在這裡插入圖片描述

import numpy as np
from sklearn.pipeline import Pipeline
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error
from sklearn.linear_model import LogisticRegression
from sklearn import datasets
from sklearn.svm import SVC
from sklearn.ensemble import VotingClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier



digits=datasets.load_iris()
X=digits.data
y=digits.target
# print(y.dtpye)
# print(y)

train_X,test_X,train_y,test_y = train_test_split(X,y,test_size=0.2,random_state=666)
bagging_clf=BaggingClassifier(DecisionTreeClassifier(),n_estimators=500,max_samples=100,bootstrap=True,oob_score=True,n_jobs=-1)

bagging_clf.fit(X,y)
print(bagging_clf.oob_score_)
# print(dt_reg.score(train_X, train_y))



在這裡插入圖片描述

相關文章