è¤æ°ã©ãã«ã®åé¡åé¡ãè©ä¾¡ãããã¨æã£ã¦Mean Average Precisionãè¨ç®ãããã¨æã£ãããPythonã®æ©æ¢°å¦ç¿ã©ã¤ãã©ãªã®scikit-learn(sklearn)ã«ã¯average_precision_score()é¢æ°ã¨label_ranking_average_precision_score()é¢æ°ããã£ã¦ã©ãããéããããã®ãããã¥ã¡ã³ããèªãã§ããã¾ãã¡ããããããªãã£ãã®ã§èª¿ã¹ã¾ãã
ã¨ããããæåã«çµè«ãæ¸ãã¦ããã¨ãè¤æ°ã©ãã«ã®åé¡åé¡ã§ãã使ãããMean Average Precisionã®è¨ç®ã«ã¯label_ranking_average_precision_score()é¢æ°ã使ãã°ãããã
追è¨: ãã¼ã¸ã§ã³0.19ããã©ã¡ããåãæåã«ãªã£ããããªã®ã§æ³¨æ(å ã ã®label_ranking_average_precision_score() é¢æ°ã¨åæ§ã®è¨ç®)
ãªã³ã¯å
ã®Notesã®é¨å
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html
Changed in version 0.19: Instead of linearly interpolating between operating points, precisions are weighted by the change in recall since the last operating point.
Mean Average Precision (MAP) ã¨ã¯
æ å ±æ¤ç´¢(IR)ãæ©æ¢°å¦ç¿ã®åéã§ä½¿ãããè©ä¾¡å°ºåº¦ãã¹ã³ã¢ä»ãã®åºåã«ã¤ãã¦ãæ£è§£ã®ãã®ãä¸ä½ã®ã¹ã³ã¢ã§ããã»ã©å¤§ããªå¤ã«ãªã(0ãã1ã®å¤ãåã) æ©æ¢°å¦ç¿ã§ã¯ä¸ã¤ã®äºä¾ã«è¤æ°ã®æ£è§£ã©ãã«ãã¤ãããã¦ããmulti labelã®ã¿ã¹ã¯ã§ç¨ãããã¦ããã®ãè¦ãããPrecisionã¨Recall
æåã«Precisionã¨ã¯ä½ãã«ã¤ãã¦è»½ã説æãã¾ã æ©æ¢°å¦ç¿ãªã©ã®ã·ã¹ãã ã§ãã¼ã¿ãç®çã®ã©ãã«(æ£ä¾)ã¨ãã®ä»ã®ã©ãã«(è² ä¾)ã«åé¡ããæãæ£ä¾ã¨å¤å®ãããã®ã®ãã¡å®éã«æ£ä¾ã ã£ããã®ã®å²åãPrecisionã§ã $$\text{precision} = \frac{|\{\text{æ£ä¾ã¨å¤å®ããããã®ã®ãã¡å®éã«æ£ä¾ã§ãã£ããã®}\}|}{|\{\text{æ£ä¾ã¨å¤å®ããããã®}\}|}$$ åç´ãªæ£è§£çã§ã¯ãªãPrecisionã使ã£ã¦å¬ããæã¯ãä¾ãã°ãã¼ã¿ä¸ã®ç®çã§ãªãã©ãã«(è² ä¾)ã®æ¯çãé常ã«å¤§ããå ´åã«å ¨é¨ãè² ä¾ã¨åé¡ãã¦ãé«ãæ£è§£çã«ãªã£ã¦ãã¾ãå ´åãªã©ãããã¾ã éã«ã·ã¹ãã ãæ£ä¾ã¨å¤å®ãããã®ããè©ä¾¡ç¨ã®ãã¼ã¿ã»ããã®æ£ä¾ã®ãã¡ã©ããããã®å²åãã«ãã¼ãã¦ããã®ãã示ãè©ä¾¡å°ºåº¦ããããããã¯Recallã¨å¼ã°ãã¾ã $$\text{recall} = \frac{|\{\text{æ£ä¾ã¨å¤å®ããããã®}\}|}{|\{\text{ãã¼ã¿ã»ããä¸ã«å«ã¾ããæ£ä¾}\}|}$$ Precisionãæ£ç¢ºããRecallãã«ãã¼ççãªãã®ã表ãã¦ãã¾ãAverage Precision
次ã«Average Precision (AP) ã«ã¤ãã¦èª¬æãã¾ã Average Precisionã¯PrecisionãRecallã«ã¤ãã¦å¹³åãã¨ã£ããã®ã§ã Precisionã¨Recallã軸ã«ãã¦Precision-Recall curveã®ã°ã©ããæ¸ããã¨ãã®æ²ç·ä»¥ä¸ã®é¨åã®é¢ç©(AUC, Area Under the Curve)ãAverage Precisionã«ãªãã¾ã(以ä¸ã®ã°ã©ãã ã¨æãç·ã§ãã) ã¡ããã¨è¨ç®ããã«ã¯ç©åçãªè¨ç®ãå¿ è¦ã«ãªã(ï¼)ã£ã½ãã§ãããè¿ä¼¼å¤ã®è¨ç®ã¨ãã¦(ï¼)以ä¸ã®ãããªå¼ã使ããã¦ããã®ãããè¦ããã¾ã åºåãã¹ã³ã¢ä¸ä½é ã«ä¸¦ã¹ãæã«kçªç®ã®åºåãæ£ä¾ãªã1ãè² ä¾ãªã0ã«ãªãé¢æ°ã\(I(k)\)ã¨å®ç¾©ããæ $$\text{Average Precision} = \frac{\sum_k \text{kçªç®ã¾ã§ã®åºåã§è¨ç®ããPrecision} \times I(k)}{|\{\text{ãã¼ã¿ã»ããä¸ã®æ£ä¾}\}|}$$ è¤æ°ã©ãã«ã®åé¡ã®è©ä¾¡ã§ã¯ãã¼ã¿ã®åäºä¾ãã¨ã«ãæ£è§£ã®ã©ãã«ãæ£ä¾ãã以å¤ãè² ä¾ã¨ã¿ãªãã¦Average Precisionãè¨ç®ãã¾ã ç°¡åãªä¾ã¨ãã¦ä»¥ä¸ã®è¡¨ã®ãã¼ã¿ã®Average Precisionãè¨ç®ãã¦ã¿ã¾ãã©ãã«ã®ç¨®é¡ | ã©ãã«ãã¤ãã¦ããã(ã¤ãã¦ããã°1) | åºåãããã¹ã³ã¢ |
---|---|---|
赤ã | 1 | 1 |
丸ã | 0 | 0.8 |
éã | 1 | 0.6 |
è¾ã | 0 | 0.4 |
scikit-learnã®é¢æ°
ããããæ¬é¡ã«å ¥ãã¾ã sklearnã«ã¯average_precision_score()é¢æ°ã¨label_ranking_average_precision_score()é¢æ°ã¨ããä¼¼ããããªååã®é¢æ°ããããã©ã¡ãã使ãã°ããã®ãã¡ãã£ã¨æ··ä¹±ãã¾ãã ããã¥ã¡ã³ããè¦ãã¨ã両æ¹å ±é©åãªå¼æ°ã渡ãã°MAPãè¨ç®ã§ãããã§ããå®è¡ãã¦ã¿ãã¨éãå¤ã«ãªãã¾ãfrom sklearn.metrics import label_ranking_average_precision_score, average_precision_score average_precision_score([1, 0, 1, 0], [1, 0.8, 0.6, 0.4], average='samples') #0.79166666666666663 label_ranking_average_precision_score([[1, 0, 1, 0]], [[1, 0.8, 0.6, 0.4]]) #0.83333333333333326ããããããªããªã£ã¦ããã®ã§ã½ã¼ã¹ã³ã¼ããèªãã§èª¿ã¹ã¦ã¿ã¾ãã ããã¨ä»¥ä¸ã®å¼ã®å®ç¾©ã¨çããè¨ç®ããã¦ããããªã®ã¯label_ranking_average_precision_score()é¢æ°ã®æ¹ã§ãã $$\text{Average Precision} = \frac{\sum_k \text{kçªç®ã¾ã§ã®åºåã§è¨ç®ããPrecision} \times I(k)}{|\{\text{ãã¼ã¿ã»ããä¸ã®æ£ä¾}\}|}$$ ä¸ã®å¼ã§ã¯å®ã¯é¢ç©ã以ä¸ã®ç»åã®ããã«é·æ¹å½¢ã§è¿ä¼¼ãã¦è¨ç®ãã¦ãã¾ã éã«average_precision_score()é¢æ°ã®æ¹ã§ã¯ãnumpy.trapz()é¢æ°ã使ã£ã¦é¢ç©ã®è¨ç®ãå°å½¢ã§è¿ä¼¼ãã¦è¨ç®ãã¦ãã¾ãã ã¤ã¾ãããæå³average_precision_score()é¢æ°ã®æ¹ãæ£ç¢ºãªè¨ç®ããã¦ããã¨ãããã¨ã«ãªãã¾ã ä¸åå¼·ã®ããAverage Precisionã®å®ç¾©ã¨ãã¦ä»¥ä¸ã®ãããªå®ç¾©ããç¥ããªãã£ãã®ã§ãããå®éã«ã¯ä»¥ä¸ã®å¼ã¯è¿ä¼¼å¤ã®è¨ç®ããã¦ããã¨ãããã¨ã£ã½ãã§ã $$\text{Average Precision} = \frac{\sum_k \text{kçªç®ã¾ã§ã®åºåã§è¨ç®ããPrecision} \times I(k)}{|\{\text{ãã¼ã¿ã»ããä¸ã®æ£ä¾}\}|}$$