ã¯ããã«
ããã«ã¡ã¯ãBASEã®DataStrategyãã¼ã ã§æ©æ¢°å¦ç¿ã触ã£ã¦ãã竹å ã§ãã
æ©æ¢°å¦ç¿ã¨ããã°LLMãDiffusionã¢ãã«ãªã©çæã¢ãã«ã®çºå±ãç®è¦ã¾ããæ¨ä»ã§ããããã®ä¸æ¹ã§æ§é åãã¼ã¿ã«å¯¾ãã¦ç¹å¾´éã¨ã³ã¸ãã¢ãªã³ã°ãè¡ããCVãåã£ã¦ãLightGBMãªã©ã®ä¾¿å©ãªæ±ºå®æ¨ãã¼ã¹ã®ãã¬ã¼ã ã¯ã¼ã¯ã«æãã¦ãã§ããã¢ãã«ã®åºåãåå³ããæã«ã¯è´å½çãªãªã¼ã¯ã«æ°ä»ãé ãæ±ããã¨ãã£ãçéã®ã¢ããã¼ãã¯ç¸å¤ãããç¾å½¹ã§ãå®åã«é¢ãã¦ããã°å½åãä¸è©±ã«ãªãæ©ä¼ãæ¸ããã¨ã¯ãªãããªã¨ããæ°ããã¦ãã¾ãã
ä»åã¯ãããã£ãã¯ã©ã¹åé¡ã¢ãã«ã«ãããæ§è½ã®è©ä¾¡ææ¨ã®1ã¤ã§ãããROCæ²ç·ãAUCãPRæ²ç·ã¨ãã£ãæ¦å¿µã«ã¤ãã¦æ¯ãè¿ãã¤ã¤ãå®åä¸ãã°ãã°è¦ãããä¸åè¡¡ãã¼ã¿ã«é©ç¨ããéã®æ³¨æç¹ãªã©ã«ã¤ãã¦ã軽ãã·ãã¥ã¬ã¼ã·ã§ã³ã交ãã¤ã¤æãä¸ãã¦ã¿ããã¨æãã¾ãã
ROCæ²ç·
2ã¯ã©ã¹åé¡å¨ã®æ§è½ãè©ä¾¡ããéã«ãã使ç¨ããããã¼ã«ã¨ãã¦ROC Operating Characteristic)æ²ç·ãæãããã¾ãã
ROCæ²ç·ã¯ç¸¦è»¸ã«åç¾ç(Recall)ã横軸ã«å½é½æ§ç(False Positive Rate)ãã¨ããããããã®æ¤åºé¾å¤ã«å¯¾ããåç¾çãå½é½æ§çããããããããã¨ã§å¾ãããæ²ç·ã§ããROCæ²ç·ã®ä¸å´ã®é åã®é¢ç©ãAUC(Area Under the Curve)ã¨å¼ã³ããã®é¢ç©ã®å¤§ããã«ãã£ã¦åé¡å¨ã®æ§è½ã®é«ããã¤ã¾ããã®åé¡å¨ãã©ã®ç¨åº¦ãã¾ãæ£ä¾ã¨è² ä¾ãåé¢ã§ãã¦ããããè©ä¾¡ãããã¨ãã§ãã¾ãã
åããã¼ã¿ã»ããã«ãããç°ãªã2ã¤ã®ã¢ãã«ã®æ§è½ãæ¯è¼ããéããåç¾çã¨å½é½æ§çã®ãã¬ã¼ããªããèæ ®ããé©åãªé¾å¤ã決å®ããéã«ROCæ²ç·ã®ããããã¯æå¹ãªé¸æè¢ã®1ã¤ã¨ãªãã¾ãã
ä¸åè¡¡ãã¼ã¿ã«ããã¦ROCæ²ç·ãæ±ãéã®æ³¨æç¹
å®åã«ããã¦2ã¯ã©ã¹åé¡å¨ãé©ç¨ããä¾ã¯ããããããã¾ãããä¾ãã°ãããå·¥å ´ã®é¨åçç£ã©ã¤ã³ã«ããã¦ãããç¨ã«çºçããä¸è¯åãæ¤ç¥ãããã¨ãã£ãä¸è¯åæ¤ç¥ãç°å¸¸æ¤ç¥ãä¸æ£æ¤ç¥ãªã©ã®æèã«ããã¦ã¯ãæ£ä¾ã«å¯¾ãã¦è² ä¾ã®ãµã¤ãºã極端ã«å¤§ãããããããä¸åè¡¡ãã¼ã¿ãæ±ããã¨ããã°ãã°ããã¾ãã
ãããã極端ã«ä¸åè¡¡ãªãã¼ã¿ã«ããã¦ã¯ãROCæ²ç·ã«ãããAUCã®ææ¨ããã¾ãæ©è½ããªããã¨ãããã¾ãã
å ·ä½çã«ã¯ROCæ²ç·ã¯é©åç(Precision)ã®ææ¨ãå«ãã§ããªãããããæ£ããæ¤åºã§ããæ£ä¾ã«å¯¾ãã¦ãå·»ãè¾¼ãã§æ¤åºãã¦ãã¾ã£ãè² ä¾ãã©ãã ãå¤ãããã¨ããç¹ãèæ ®ããããçµæã¨ãã¦é常ã«å¤ãã®å½é½æ§ãçºçãã¦ãã¾ã£ã¦ãã¦ãAUCã¯é«ãå¤ã示ãã¦ãã¾ããã¨ãããã¾ãã
å
ã»ã©ã®å·¥å ´ã®ä¸è¯åæ¤ç¥ã®ä¾ã§è¨ãã°ãAUCã®å¤ã¯ã»ã¼1ã§ããã«ãé¢ãããã稼åããã¦ã¿ããä¸è¯åã®è¦éãã¯å°ãªããã®ã®ã大éã®å½é½æ§ãçºçãã¦ãã¾ããã¨ã§ãå¾ç¶ã®ç®è¦ãã§ãã¯ã®å·¥ç¨ããã³ã¯ããã¦ãã¾ãããã¨ãã£ãåé¡ãçãããã¦ãã¾ãå¯è½æ§ãããã¾ãã
ã¾ãããã°ãã°ããããä¸åè¡¡ãã¼ã¿ã«ããã¦ã¯ããç¨åº¦ã®æ§è½ã§ããã°ã©ã®ã¢ãã«ã®AUCãã»ã¼1ã«è¿ãå¤ãåããããªROCæ²ç·ãããããããã¦ãã¾ããç°ãªãã¢ãã«ãæ¯è¼ãããã¨ãé£ãããã¨ãããã¾ãã
PRæ²ç·
ROCæ²ç·ã¨åæ§ãªæ¦å¿µã¨ãã¦ãã°ãã°ç¨ãããããã¨ãããPR(Precision-Recall)æ²ç·ã¯ã縦軸ã«åç¾ç(Recall)ã横軸ã«é©åç(Precision)ãã¨ã£ããã®ã§ãããã¡ãã¯ROCæ²ç·ã¨ã¯ç°ãªãã横軸ã«é©åçãæ¡ç¨ãã¦ãããããæ£ããæ¤åºã§ããæ£ä¾ã«å¯¾ãã¦ãå·»ãè¾¼ãã§æ¤åºãã¦ãã¾ã£ãè² ä¾ãã©ãã ãå¤ããããåæ ãããã¨ãã§ãã¾ãã
ãã®ãããROCæ²ç·ã«ãããé«ãAUCã観測ã§ãã¦ãã¦ãããã¼ã¿ã«ä¸åè¡¡æ§ãã¿ãããå ´åã¯PRæ²ç·ããããããã¦ã¿ããã¨ã§ã¢ãã«ã®æ§è½ã«é¢ãã示åãå¾ãããå¯è½æ§ãããã¾ããã¾ããROCæ²ç·ã«ãããAUCã«ã¤ãã¦ã¯å·®ãã»ã¨ãã©è¦ãããªã2ã¤ã®ã¢ãã«ã®æ§è½ãæ¯è¼ããå ´åã«ããã¦ããPRæ²ç·ã«ãããæ¹åãã¿ãããã±ã¼ã¹ãããã¾ãã
ãã¼ã¿ã«ä¸åè¡¡æ§ãã¿ãããå ´åã¯ROCæ²ç·ã ãã§ãªãPRæ²ç·ã®ãããããè¦ã¦ããã¨è¯ãããããã¾ããã
å®é¨
ç°¡åãªã·ãã¥ã¬ã¼ã·ã§ã³ãè¡ããã¨ã§ãä¸åè¡¡ãã¼ã¿ã«ãããROCæ²ç·ã¨PRæ²ç·ã®æ§è³ªã«ã¤ãã¦è»½ãæ¤è¨¼ãã¦ã¿ã¾ãã
ã¾ããæ£ä¾ã¯å¹³å3ãè² ä¾ã¯å¹³å1ã§åæ£ã¯å ±ã«1ã®æ£è¦åå¸ã«ããããç¹å¾´éXãã¤ãã¨ãæ¢ç¥ã¨ããä¸ã§ãXãé¾å¤ä»¥ä¸ã®ãã®ãæ£ä¾ãé¾å¤ä»¥ä¸ã®ãã®ãè² ä¾ã¨ãã¦åé¡ããã¢ãã«ãèãã¾ãã
ãã®ä¸ã§ãæ£ä¾ã®ãã¼ã¿ã¯1000件ã«åºå®ããè² ä¾ã®æ¹ã¯æ£ä¾ã®ä»¶æ°ã®1åã10åã100åã1000åã®4ã¤ã®ãã¿ã¼ã³ã§çæãããã®ã¢ãã«ã®æ§è½ãè©ä¾¡ãããã¨ãèãã¾ãã
ä¸å³ã¯çæããããã¼ã¿ã®ãã¹ãã°ã©ã ã§ãããè² ä¾ãå¤ããªãã¨æ½°ãã¦è¦ããªããªã£ã¦ãã¾ãããæ£ä¾ã®ãã¼ã¿ã¯4ãã¿ã¼ã³ã§å
¨ã¦åããã®ã使ç¨ãã¦ãã¾ãã
ç·è²ã®ç¹ç·ã¯é¾å¤ã示ãã¦ãããã¢ãã«ã¯ããããå³å´ã®ãã®ãæ£ä¾ãå·¦å´ã®ãã®ãè² ä¾ã¨ãã¦èå¥ãããã¨ã«ãªãã¾ãã
å³ã§ã¯é¾å¤1.5ã®ä¾ã示ãã¦ãã¾ãããROCæ²ç·ãPRæ²ç·ãããããããéã¯ãã®ç·è²ã®ç¹ç·ã左端ããå³ç«¯ã¸ç§»åãããéã®åææ¨ãè¨ç®ãããã¨ã«ãªãã¾ãã
# ã³ã¼ãä¾ import numpy as np import matplotlib.pyplot as plt # æ£è¦åå¸ã«å¾ãä¹±æ°ãçæ ratios = [1, 10, 100, 1000] sample_size_positives = 1000 positives = np.random.normal(3, 1, sample_size_positives) dataset = {} for r in ratios: sample_size_negatives = sample_size_positives * r negatives = np.random.normal(0, 1, sample_size_negatives) dataset[r] = (sample_size_negatives, positives, negatives) # ratio=1ã®å ´å ratio = 1 _, positives, negatives = dataset[ratio] fig, ax = plt.subplots() ax.hist(positives, bins=100, color="r", alpha=0.5, label="positives") ax.hist(negatives, bins=100, color="b", alpha=0.5, label="negatives") ax.axvline(x=threshold_example, color="g", linestyle="--", label=f"{threshold_example=}") ax.legend(loc="upper right") ax.title.set_text(f"{ratio=}")
ã¡ãªã¿ã«ãã°ã©ãã«ãããåææ¨ã®ã¤ã¡ã¼ã¸ã¯ä»¥ä¸ã®ãããªãã®ã¨ãªãã¾ãã
åç¾ç(Recall) = (ç¹ç·å³å´ã®èµ¤è²é¨åã®é¢ç©) / (赤è²é¨åå
¨ä½ã®é¢ç©)
å½é½æ§ç(False Positive Rate) = (ç¹ç·å³å´ã®éè²é¨åã®é¢ç©) / (éè²é¨åå
¨ä½ã®é¢ç©)
é©åç(Precision) = (ç¹ç·å³å´ã®èµ¤è²é¨åã®é¢ç©) / {(ç¹ç·å³å´ã®èµ¤è²é¨åã®é¢ç©) + (ç¹ç·å³å´ã®éè²é¨åã®é¢ç©)}
ã¾ãã4ã¤ã®ãã¿ã¼ã³ã«ã¤ãã¦ãROCæ²ç·ããããããã¦ã¿ã¾ãã
ROCæ²ç·ã¯ã©ã®ãã¿ã¼ã³ã«ã¤ãã¦ãã»ã¼åãã§ãå·¦ä¸ã«å¼µãä»ããããªå½¢ãã¨ã£ã¦ãããAUCã¯ã»ã¼1ã«è¿ãå¤ãåã£ã¦ãããã¨ããããã¾ããã¤ã¾ããROCæ²ç·ã¯ãã¼ã¿ã®ä¸åè¡¡æ§ã®å½±é¿ãã»ã¼åæ ãã¦ããªããã¨ããããã¾ãã
# ã³ã¼ãä¾ # ROC curve threshols = np.linspace(-5, 5, 1000) threshold_example = 1.5 fig, ax = plt.subplots() ax.plot([0, 1], [0, 1], linestyle="--", color="g", label="random") for i, r in enumerate(ratios): recalls = [] fprs = [] sample_size_negatives, positives, negatives = dataset[r] for j in range(len(threshols)): recalls.append(np.sum(positives > threshols[j]) / sample_size_positives) fprs.append(np.sum(negatives > threshols[j]) / (sample_size_negatives)) ax.scatter(fprs, recalls, color=plot_colors[i], label=f"ratio={r}", s=3) # é¾å¤threshold_exampleã®æã®recallã¨fpr ax.scatter( [np.sum(negatives > threshold_example) / sample_size_negatives], [np.sum(positives > threshold_example) / sample_size_positives], color="r", s=15) ax.legend(loc="lower right") plt.xlabel("FPR") plt.ylabel("Recall")
次ã«4ã¤ã®ãã¿ã¼ã³ã«ã¤ãã¦PRæ²ç·ããããããã¦ã¿ã¾ãã
PRæ²ç·ã«ã¤ãã¦ã¯ROCæ²ç·ã¨ã¯ç°ãªãã4ã¤ã®ãã¿ã¼ã³ããããã§å ¨ãç°ãªãæ²ç·ãããããããã¦ãããROCæ²ç·ã¨æ¯è¼ãã¦ãã¼ã¿ã®ä¸åè¡¡æ§ã®å½±é¿ãåæ ãããããã¨ããããã¾ãã
å³ã®èµ¤ãç¹ã«ãããåãé¾å¤1.5ã§è¦ã¦ã¿ãã¨åç¾çã¯å ¨ã¦ã®ãã¿ã¼ã³ã§åãå¤ãåã£ã¦ãã¾ãããé©åçã«ããã¦ã¯ãã¼ã¿ãä¸åè¡¡ã«ãªãã«ã¤ãã¦ä½ãå¤ãåããã¨ããããã¾ãã
# ã³ã¼ãä¾ # PR curve fig, ax = plt.subplots() for i, r in enumerate(ratios): recalls = [] precisions = [] sample_size_negatives, positives, negatives = dataset[r] for j in range(len(threshols)): recalls.append(np.sum(positives > threshols[j]) / sample_size_positives) precisions.append(np.sum(positives > threshols[j]) / (np.sum(positives > threshols[j]) + np.sum(negatives > threshols[j]))) ax.scatter(precisions, recalls, color=plot_colors[i], label=f"ratio={r}", s=3) # é¾å¤1ã®æã®é©åçã¨åç¾ç plt.scatter( [np.sum(positives > threshold_example) / (np.sum(positives > threshold_example) + np.sum(negatives > 1.5))], [np.sum(positives > threshold_example) / sample_size_positives], color="r", s=15) ax.legend(loc="lower right") plt.xlabel("Precision") plt.ylabel("Recall")
æå¾ã«
ä»åã¯2ã¯ã©ã¹åé¡ã«ãããããã¼ã¿ã®ä¸åè¡¡æ§ã¨ROCæ²ç·ããã³PRæ²ç·ã®é¢ä¿æ§ã«ã¤ãã¦æãä¸ãã¦ã¿ã¾ããã
ä¸è¬çã«ã¯ã¢ãã«ã®æ§è½è©ä¾¡ã«ã¯ROCæ²ç·ãç¨ãããã¨ãå¤ãæ°ããã¾ãããPRæ²ç·ã®åå¨ãé ã«å
¥ãã¦ããã¨ãä¸åè¡¡ãªãã¼ã¿ãæ±ãéã«å½¹ã«ç«ã¤ããããã¾ããã
ä¸å¿é©åçãæ±ãéã®æ³¨æç¹ãæãã¦ããã¨ãæ¤è¨¼ç¨ãã¼ã¿ã«ãããè² ä¾ãæ¬çªã®ãã¼ã¿ãããã¦ã³ãµã³ããªã³ã°ããã¦ããå ´åãç®åºãããé©åçããã®ãµã³ããªã³ã°æ¯çã«ä¾åãã¦ãã¾ãç¹ãããã¾ãã
ä¾ãã°è² ä¾ãæ¬çªã®ãã¼ã¿ãã1/rã®ä»¶æ°ã ãã©ã³ãã ãµã³ããªã³ã°ããã¦ããå ´åãå®éã®é©åçã¸è£æ£ããè¨ç®å¼ã¨ãã¦ã¯ãæ¤è¨¼ç¨ãã¼ã¿ã«ãããå½é½æ§(False Positives)ã®ä»¶æ°ãN(FP)ãªã©ã¨ãã¦
ã¨ãã£ãå½¢ãèãããã¾ããè² ä¾ãå§åçã«å¤ãã±ã¼ã¹ã§ã¯ãç¶æ³ã«å¿ãã¦åæ¯ã®N(TP)ã0ã«è¿ä¼¼ãã¦ãã¾ã£ã¦ãæ¤è¨¼ç¨ãã¼ã¿ã«ãããé©åçã«1/rããããå¤ãçã®é©åçã¨ãã¦ãã¾ã£ã¦ãè¯ãããããã¾ããã
ã¾ããå®åã«ããã¦ã¯å½é½æ§ãå½é°æ§ã®æ°ã ãã§è©ä¾¡ããã®ã§ã¯ãªãããã®è³ªã誤åé¡ã³ã¹ãã®é対称æ§ãªã©ã«ã注æãæããã¨ãéè¦ã§ããä¸è¯åæ¤ç¥ã®ä¾ã§ããã°ãå½é°æ§ã®ä¸ã«æ·±å»ãªæ¬ é¥ãè¦éãã¦ããä¾ããªãããä¸æ£æ±ºæ¸ã®æ¤ç¥ã§ããã°å¤§ããªæ害ããããã決æ¸ãè¦éãã¦ããä¾ããªãããã¨ãã£ããµã³ãã«ãã¨ã«ç°ãªã誤åé¡ã³ã¹ãã«ã¤ãã¦ãåååå³ããå¿ è¦ãããã¾ãã
æå¾ã¨ãªãã¾ãããDataStragetyãã¼ã ã§ã¯BASEã«ããããã¼ã¿åæåºç¤ã®æ¹åãä¸ç·ã«è¡ã£ã¦ããã¡ã³ãã¼ãåéãã¦ãã¾ãããèå³ã®ããæ¹ã¯æ°è»½ã«ãå¿åãã ããï¼
A-1.Tech_ãã¼ã¿ã¨ã³ã¸ã㢠/ BASEæ ªå¼ä¼ç¤¾
ææ¥ã®BASEã¢ããã³ãã«ã¬ã³ãã¼ã¯@h7jin16ããã¨@u_hayato13ããã®è¨äºã§ããã楽ãã¿ã«ï¼
åèè³æ
Wikipedia,Receiver operating characteristic
https://en.wikipedia.org/wiki/Receiver_operating_characteristic
scikit-learn,precision_recall_curve
https://scikit-learn.org/1.5/modules/generated/sklearn.metrics.precision_recall_curve.html
Google,Machine Learning Crash Course,roc-and-auc
https://developers.google.com/machine-learning/crash-course/classification/roc-and-auc?hl=en