반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

sklearn.ensemble .GradientBoostingClassifier 본문

[AI]/python.sklearn

sklearn.ensemble .GradientBoostingClassifier

givemebro 2020. 4. 21. 19:59
반응형
  • 그래디언트 부스팅도 랜덤 포레스트 처럼 나무를 여러개 만듬.
  • 하지만, 한꺼번에 나무를 만들지 않고 나무를 하나 만든 다음 그것의 오차를 줄이는 방법으로 다음 나무를 만듬
  • 이런 과정을 단계적으로 진행
  • 그래디언트 부스팅은 머신러닝 경연대회에서 우승을 많이 차지함
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import GradientBoostingClassifier

cancer = load_breast_cancer()

 

 

X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target)

model =GradientBoostingClassifier()
model.fit(X_train, y_train)

train_score = model.score(X_train, y_train)
test_score = model.score(X_test, y_test)
display(train_score, test_score)

# 1.0
# 0.972027972027972

 

model
'''
GradientBoostingClassifier(criterion='friedman_mse', init=None,
              learning_rate=0.1, loss='deviance', max_depth=3,
              max_features=None, max_leaf_nodes=None,
              min_impurity_decrease=0.0, min_impurity_split=None,
              min_samples_leaf=1, min_samples_split=2,
              min_weight_fraction_leaf=0.0, n_estimators=100,
              presort='auto', random_state=None, subsample=1.0, verbose=0,
              warm_start=False)
'''

 

X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target)

model =GradientBoostingClassifier(n_estimators=1000, max_depth=1) 
# n_estimators : 나무 수 / max_depth : 최대 depth / learning_rate : 학습률(얼마나 빨리 오류를 줄일지)
model.fit(X_train, y_train)

train_score = model.score(X_train, y_train)
test_score = model.score(X_test, y_test)
display(train_score, test_score)

# 1.0
# 0.972027972027972
반응형
Comments