여러 개의 의사결정트리를 생성 > 투표를 시켜 다수결로 결정
복원 추출 방식
로또를 뽑는 다고 가정할 시 10번을 뽑고 다시 10번 구슬을 넣을 경우
> 중복된 숫자가 발생할 수 있음
비 복원추출방식
로또를 뽑는 다고 가정할 시 10번을 뽑고 다시 10번 구슬을 제외할 경우
Decision Tree 여러개로 숲(forest)을 만든다
Bagging, Boosting > Ensemble
Bootstrapping - Training data 에서 동일 한 dataset을 중복 허용하여 랜덤하게 추출하는 것
outliner 영향을 받지 않음
선형 비선형 관계 없음
Decision tree 과적함 overfitting 보완
Boosting model 이해하기 위한 알고리즘
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets, metrics
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
iris = datasets.load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,random_state=123)
model = RandomForestClassifier(criterion='entropy', n_estimators=8, n_jobs=-1, random_state=124)
# n_estimators 결정트리 Desicion tree 개수
# n_jobs 작업할 cpu : -1 은 가용할수 있는 모든 cpu를 사용하라는 값
model.fit(X_train,y_train)
new_data = [[2.1,3.4,4.6,7.1],[3.4,4.1,6.7,2.7]]
new_pred = model.predict(new_data)
y_pred = model.predict(X_test)
print(model.score(X_test, y_test))
print(model.score(X_train, y_train))
metrics.classification_report(y_test, y_pred, target_names=iris.target_names)
precision recall f1-score support
setosa 1.00 1.00 1.00 18
versicolor 0.71 1.00 0.83 10
virginica 1.00 0.76 0.87 17
accuracy 0.91 45
macro avg 0.90 0.92 0.90 45
weighted avg 0.94 0.91 0.91 45
'Colab > 머신러닝' 카테고리의 다른 글
11. 랜덤 포레스트 (random forest) 03 (0) | 2023.03.09 |
---|---|
10. 랜덤 포레스트 (random forest) 02 (0) | 2023.03.09 |
08. 결정 트리 (Decision Tree) 02 (0) | 2023.03.08 |
07. 결정 트리 (Decision Tree) 01 (0) | 2023.03.08 |
06. K-최근접 이웃 회귀 K-NN Regression (0) | 2023.03.06 |