pip install xgboost
conda install py-xgboost
import time
import warnings
from xgboost import XGBRFClassifier
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import LabelEncoder # 주의!
warnings.filterwarnings('ignore')
le = LabelEncoder()
y_train = le.fit_transform(y_train) # array형태로
start_time = time.time()
xgb = XGBRFClassifier(n_estimators=400, learning_rate=0.1, max_depth=3)
xgb.fit(X_train.values, y_train)
print('Fit time: ', time.time() - start_time)
y_pred = xgb.predict(X_test.values)
y_pred = le.inverse_transform(y_pred) # 다시 le.inverser_transform으로 변환 후 실행해줘야 한다!!
print(accuracy_score(y_test, y_pred))
'''
Fit time: 282.9081630706787
0.8666440447913132
'''
import time
import warnings
from xgboost import XGBRFClassifier
from sklearn.metrics import accuracy_score
warnings.filterwarnings('ignore')
le = LabelEncoder()
y_train = le.fit_transform(y_train)
evals= [(X_test.values, y_test)]
start_time = time.time()
xgb = XGBRFClassifier(n_estimators=400, learning_rate=0.1, max_depth=3)
xgb.fit(X_train.values, y_train, eval_set=evals) # 조기 종료 조건과 검증데이터를 지정, early_stopping_rounds 찾기
y_pred = xgb.predict(X_test.values)
y_pred = le.inverse_transform(y_pred) # 다시 le.inverser_transform으로 변환 후 실행해줘야 한다!!
print('Fit time: ', time.time() - start_time)
print(accuracy_score(y_test, y_pred))
Reference
1) 제로베이스 데이터스쿨 강의자료