분석시각화 대회 코드 공유 게시물은
내용 확인 후
좋아요(투표) 가능합니다.
평가 산식 안내
이번 '운수종사자 인지적 특성 데이터를 활용한 교통사고 위험 예측 AI 경진대회'에 실제 적용되고 있는 평가 산식 코드를 공개합니다.
참가자 여러분들께서는 모델 성능 개선에 해당 평가 산식 코드를 활용하실 수 있습니다.
이번 산식은 여러 평가 지표를 조합하여 모델의 예측 성능과 예측의 신뢰도를 함께 고려하여 평가하기 위해 구성되었습니다.
산식은 AUC(Area Under the Curve), Brier Score, ECE(Expected Calibration Error) 세 가지 주요 성능 지표를 결합합니다.
산식은 0 ~ 1 의 범위로 산출되며, 산식 점수가 0 에 가까울수록 좋은 모델 성능을 뜻합니다.
import numpy as np
from sklearn.calibration import calibration_curve
from sklearn.metrics import mean_squared_error
from sklearn.metrics import roc_auc_score
import pandas as pd
def expected_calibration_error(y_true, y_prob, n_bins=10):
prob_true, prob_pred = calibration_curve(y_true, y_prob, n_bins=n_bins, strategy='uniform')
bin_totals = np.histogram(y_prob, bins=np.linspace(0, 1, n_bins + 1), density=False)[0]
non_empty_bins = bin_totals > 0
bin_weights = bin_totals / len(y_prob)
bin_weights = bin_weights[non_empty_bins]
prob_true = prob_true[:len(bin_weights)]
prob_pred = prob_pred[:len(bin_weights)]
ece = np.sum(bin_weights * np.abs(prob_true - prob_pred))
return ece
def auc_brier_ece(answer_df, submission_df):
# Check for missing values in submission_df
if submission_df.isnull().values.any():
raise ValueError("The submission dataframe contains missing values.")
# Check if the number and names of columns are the same in both dataframes
if len(answer_df.columns) != len(submission_df.columns) or not all(answer_df.columns == submission_df.columns):
raise ValueError("The columns of the answer and submission dataframes do not match.")
submission_df = submission_df[submission_df.iloc[:, 0].isin(answer_df.iloc[:, 0])]
submission_df.index = range(submission_df.shape[0])
# Calculate AUC for each class
auc_scores = []
for column in answer_df.columns[1:]:
y_true = answer_df[column]
y_scores = submission_df[column]
auc = roc_auc_score(y_true, y_scores)
auc_scores.append(auc)
# Calculate mean AUC
mean_auc = np.mean(auc_scores)
brier_scores = []
ece_scores = []
# Calculate Brier Score and ECE for each class
for column in answer_df.columns[1:]:
y_true = answer_df[column].values
y_prob = submission_df[column].values
# Brier Score
brier = mean_squared_error(y_true, y_prob)
brier_scores.append(brier)
# ECE
ece = expected_calibration_error(y_true, y_prob)
ece_scores.append(ece)
# Calculate mean Brier Score and mean ECE
mean_brier = np.mean(brier_scores)
mean_ece = np.mean(ece_scores)
# Calculate combined score
combined_score = 0.5 * (1 - mean_auc) + 0.25 * mean_brier + 0.25 * mean_ece
return combined_score
DACON Co.,Ltd | CEO Kookjin Kim | 699-81-01021
Mail-order-sales Registration Number: 2021-서울영등포-1704
Business Providing Employment Information Number: J1204020250004
#901, Eunhaeng-ro 3, Yeongdeungpo-gu, Seoul 07237
E-mail dacon@dacon.io |
Tel. 070-4102-0545
Copyright ⓒ DACON Inc. All rights reserved