관리 메뉴

KorSA

모델 학습 시간과 성능은 비례하지 않는다 본문

Data Analysis/Experience

모델 학습 시간과 성능은 비례하지 않는다

Praiv. 2023. 7. 17. 09:52
320x100

 

 

머신러닝 문제를 풀다가 모델의 학습 시간이 길다고 해서 성능이 좋은 건 아니라는 사실을 알게 되었다.

 

아래 코드를 통해서 여러 머신러닝 모델의 학습 시간을 측정하였다.


# 리스트 준비
models = [ran, knn, log, xgb, gbc, svc, ext, ada, gnb, gpc, bag]         
model_names = ['Random Forest', 'K Nearest Neighbour', 'Logistic Regression', 'XGBoost', 'Gradient Boosting', 'SVC', 'Extra Trees', 'AdaBoost', 'Gaussian Naive Bayes', 'Gaussian Process', 'Bagging Classifier']
scores = {}

# 모델 튜닝 및 평가
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import cross_val_predict
from sklearn import model_selection
import time

for ind, mod in enumerate(models):
    print(f"{model_names[ind]} training started...")
    start_time = time.time()
    
    mod.fit(X_train, y_train_ec1)
    acc = cross_val_score(mod, X_train, y_train_ec1, scoring = 'accuracy', cv = 10)
    scores[model_names[ind]] = acc
    
    end_time = time.time()
    elapsed_time = end_time - start_time

    print(f"{model_names[ind]} training finished!! (Elapsed Time: {elapsed_time})")

 

각 모델별 학습 시간은 아래와 같다.

 

SVC와 Gaussian Process 가 너무 오래 걸려서 기다리기 힘들었다..

그런데 각 모델별 성능을 확인해보니 반전이 있었다.

results = pd.DataFrame(scores).T
results['mean'] = results.mean(1)

result_df = results.sort_values(by='mean', ascending=False)
result_df = result_df.drop(['mean'], axis=1)
sns.boxplot(data=result_df.T, orient='h')
plt.title('Machine Learning Algorithm Accuracy Score \n')
plt.xlabel('Accuracy Score (%)')

 

5초 걸린 Gradient Boosting 과 2초 걸린 AdaBoost가 상위 1, 2위를 했고

가장 오래 걸렸던 SVC는 3등, Gaussian Process는 5등을 했다.

 

 

결론,

모델의 학습 시간과 성능은 비례하지 않는다!

 

 

 

 

728x90
728x90

'Data Analysis > Experience' 카테고리의 다른 글

Kaggle에 submit 하기  (0) 2023.07.21
Comments