About sklearn.metrics.average_precision_score documentationHow to interpret the AUC score in this case?Where to find statistically relevant documentation of common Python packages?Irregular Precision-Recall CurveNeed a Work-around for OneHotEncoder Issue in SKLearn PreprocessingSci-kit learn function to select threshold for higher recall than precisionXGBoost: Quantifying Feature Importancessklearn nmf - question about its usemodel.predict in Keras, Python errorDifference between sklearn’s “log_loss” and “LogisticRegression”?Not sure if over-fitting

About sklearn.metrics.average_precision_score documentation

What does this 'x' mean on the stem of the voice's note, above the notehead?

Very serious stuff - Salesforce bug enabled "Modify All"

Should I twist DC power and ground wires from a power supply?

How does the "reverse syntax" in Middle English work?

What does it mean for a program to be 32 or 64 bit?

Is there any official Lore on Keraptis the Wizard, apart from what is in White Plume Mountain?

Is being an extrovert a necessary condition to be a manager?

What should I wear to go and sign an employment contract?

"File type Zip archive (application/zip) is not supported" when opening a .pdf file

DISTINCT NULL return single NULL in SQL Server

Everytime I convert PDF to PNG it becomes more pixely. How can I fix it?

Bash Array of Word-Splitting Headaches

Does the Aboleth have expertise in history and perception?

Restraint classed as assault after suspecting unconsented photo

What were the "pills" that were added to solid waste in Apollo 7?

Good examples of "two is easy, three is hard" in computational sciences

Latin words remembered from high school 50 years ago

How can I prevent Bash expansion from passing files starting with "-" as argument?

Reference for electronegativities of different metal oxidation states

Why were early aviators' trousers flared at the thigh?

Why did Nick Fury not hesitate in blowing up the plane he thought was carrying a nuke?

Can 2 light bulbs of 120V in series be used on 230V AC?

Precedent for disabled Kings



About sklearn.metrics.average_precision_score documentation


How to interpret the AUC score in this case?Where to find statistically relevant documentation of common Python packages?Irregular Precision-Recall CurveNeed a Work-around for OneHotEncoder Issue in SKLearn PreprocessingSci-kit learn function to select threshold for higher recall than precisionXGBoost: Quantifying Feature Importancessklearn nmf - question about its usemodel.predict in Keras, Python errorDifference between sklearn’s “log_loss” and “LogisticRegression”?Not sure if over-fitting













2












$begingroup$


There is a example in sklearn.metrics.average_precision_score documentation.



import numpy as np
from sklearn.metrics import average_precision_score
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
average_precision_score(y_true, y_scores)
0.83


But when I plot precision_recall_curve



precision, recall, _ = precision_recall_curve(y_true, y_scores)
plt.plot( recall,precision)


I got the picture:enter image description here



why the area under the precision_recall_curve is not 0.83?










share|improve this question











$endgroup$
















    2












    $begingroup$


    There is a example in sklearn.metrics.average_precision_score documentation.



    import numpy as np
    from sklearn.metrics import average_precision_score
    y_true = np.array([0, 0, 1, 1])
    y_scores = np.array([0.1, 0.4, 0.35, 0.8])
    average_precision_score(y_true, y_scores)
    0.83


    But when I plot precision_recall_curve



    precision, recall, _ = precision_recall_curve(y_true, y_scores)
    plt.plot( recall,precision)


    I got the picture:enter image description here



    why the area under the precision_recall_curve is not 0.83?










    share|improve this question











    $endgroup$














      2












      2








      2





      $begingroup$


      There is a example in sklearn.metrics.average_precision_score documentation.



      import numpy as np
      from sklearn.metrics import average_precision_score
      y_true = np.array([0, 0, 1, 1])
      y_scores = np.array([0.1, 0.4, 0.35, 0.8])
      average_precision_score(y_true, y_scores)
      0.83


      But when I plot precision_recall_curve



      precision, recall, _ = precision_recall_curve(y_true, y_scores)
      plt.plot( recall,precision)


      I got the picture:enter image description here



      why the area under the precision_recall_curve is not 0.83?










      share|improve this question











      $endgroup$




      There is a example in sklearn.metrics.average_precision_score documentation.



      import numpy as np
      from sklearn.metrics import average_precision_score
      y_true = np.array([0, 0, 1, 1])
      y_scores = np.array([0.1, 0.4, 0.35, 0.8])
      average_precision_score(y_true, y_scores)
      0.83


      But when I plot precision_recall_curve



      precision, recall, _ = precision_recall_curve(y_true, y_scores)
      plt.plot( recall,precision)


      I got the picture:enter image description here



      why the area under the precision_recall_curve is not 0.83?







      python scikit-learn scoring






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      Ben Reiniger

      664214




      664214










      asked 6 hours ago









      disney82231disney82231

      352




      352




















          1 Answer
          1






          active

          oldest

          votes


















          3












          $begingroup$

          According to the documentation, the value is not exactly the area under curve, it is
          $$textAP = sum_n(R_n - R_n-1)P_n.$$
          which is a rectangular approximation.



          For your specific example, it is calculated as
          $$beginalign*
          textAP & = overbrace(0.5 - 0.0)times1.0^(R_2 - R_1)P_2 + overbrace(0.5 - 0.5)times 0.5^(R_3 - R_2)P_3 + overbrace(1.0 - 0.5) times0.66^(R_4 - R_3)P_4 \
          &= 0.5 + 0.00+ 0.33 = 0.83
          endalign*$$

          which is the area under the red curve as illustrated below:








          share|improve this answer









          $endgroup$








          • 3




            $begingroup$
            Beat me to it; in particular, the documentation states "This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic."
            $endgroup$
            – Ben Reiniger
            2 hours ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f52130%2fabout-sklearn-metrics-average-precision-score-documentation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3












          $begingroup$

          According to the documentation, the value is not exactly the area under curve, it is
          $$textAP = sum_n(R_n - R_n-1)P_n.$$
          which is a rectangular approximation.



          For your specific example, it is calculated as
          $$beginalign*
          textAP & = overbrace(0.5 - 0.0)times1.0^(R_2 - R_1)P_2 + overbrace(0.5 - 0.5)times 0.5^(R_3 - R_2)P_3 + overbrace(1.0 - 0.5) times0.66^(R_4 - R_3)P_4 \
          &= 0.5 + 0.00+ 0.33 = 0.83
          endalign*$$

          which is the area under the red curve as illustrated below:








          share|improve this answer









          $endgroup$








          • 3




            $begingroup$
            Beat me to it; in particular, the documentation states "This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic."
            $endgroup$
            – Ben Reiniger
            2 hours ago















          3












          $begingroup$

          According to the documentation, the value is not exactly the area under curve, it is
          $$textAP = sum_n(R_n - R_n-1)P_n.$$
          which is a rectangular approximation.



          For your specific example, it is calculated as
          $$beginalign*
          textAP & = overbrace(0.5 - 0.0)times1.0^(R_2 - R_1)P_2 + overbrace(0.5 - 0.5)times 0.5^(R_3 - R_2)P_3 + overbrace(1.0 - 0.5) times0.66^(R_4 - R_3)P_4 \
          &= 0.5 + 0.00+ 0.33 = 0.83
          endalign*$$

          which is the area under the red curve as illustrated below:








          share|improve this answer









          $endgroup$








          • 3




            $begingroup$
            Beat me to it; in particular, the documentation states "This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic."
            $endgroup$
            – Ben Reiniger
            2 hours ago













          3












          3








          3





          $begingroup$

          According to the documentation, the value is not exactly the area under curve, it is
          $$textAP = sum_n(R_n - R_n-1)P_n.$$
          which is a rectangular approximation.



          For your specific example, it is calculated as
          $$beginalign*
          textAP & = overbrace(0.5 - 0.0)times1.0^(R_2 - R_1)P_2 + overbrace(0.5 - 0.5)times 0.5^(R_3 - R_2)P_3 + overbrace(1.0 - 0.5) times0.66^(R_4 - R_3)P_4 \
          &= 0.5 + 0.00+ 0.33 = 0.83
          endalign*$$

          which is the area under the red curve as illustrated below:








          share|improve this answer









          $endgroup$



          According to the documentation, the value is not exactly the area under curve, it is
          $$textAP = sum_n(R_n - R_n-1)P_n.$$
          which is a rectangular approximation.



          For your specific example, it is calculated as
          $$beginalign*
          textAP & = overbrace(0.5 - 0.0)times1.0^(R_2 - R_1)P_2 + overbrace(0.5 - 0.5)times 0.5^(R_3 - R_2)P_3 + overbrace(1.0 - 0.5) times0.66^(R_4 - R_3)P_4 \
          &= 0.5 + 0.00+ 0.33 = 0.83
          endalign*$$

          which is the area under the red curve as illustrated below:









          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          EsmailianEsmailian

          4,519422




          4,519422







          • 3




            $begingroup$
            Beat me to it; in particular, the documentation states "This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic."
            $endgroup$
            – Ben Reiniger
            2 hours ago












          • 3




            $begingroup$
            Beat me to it; in particular, the documentation states "This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic."
            $endgroup$
            – Ben Reiniger
            2 hours ago







          3




          3




          $begingroup$
          Beat me to it; in particular, the documentation states "This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic."
          $endgroup$
          – Ben Reiniger
          2 hours ago




          $begingroup$
          Beat me to it; in particular, the documentation states "This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic."
          $endgroup$
          – Ben Reiniger
          2 hours ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f52130%2fabout-sklearn-metrics-average-precision-score-documentation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Log på Navigationsmenu

          Creating second map without labels using QGIS?How to lock map labels for inset map in Print Composer?How to Force the Showing of Labels of a Vector File in QGISQGIS Valmiera, Labels only show for part of polygonsRemoving duplicate point labels in QGISLabeling every feature using QGIS?Show labels for point features outside map canvasAbbreviate Road Labels in QGIS only when requiredExporting map from composer in QGIS - text labels have moved in output?How to make sure labels in qgis turn up in layout map?Writing label expression with ArcMap and If then Statement?

          Nuuk Indholdsfortegnelse Etyomologi | Historie | Geografi | Transport og infrastruktur | Politik og administration | Uddannelsesinstitutioner | Kultur | Venskabsbyer | Noter | Eksterne henvisninger | Se også | Navigationsmenuwww.sermersooq.gl64°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.75064°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.750DMI - KlimanormalerSalmonsen, s. 850Grønlands Naturinstitut undersøger rensdyr i Akia og Maniitsoq foråret 2008Grønlands NaturinstitutNy vej til Qinngorput indviet i dagAntallet af biler i Nuuk må begrænsesNy taxacentral mødt med demonstrationKøreplan. Rute 1, 2 og 3SnescootersporNuukNord er for storSkoler i Kommuneqarfik SermersooqAtuarfik Samuel KleinschmidtKangillinguit AtuarfiatNuussuup AtuarfiaNuuk Internationale FriskoleIlinniarfissuaq, Grønlands SeminariumLedelseÅrsberetning for 2008Kunst og arkitekturÅrsberetning for 2008Julie om naturenNuuk KunstmuseumSilamiutGrønlands Nationalmuseum og ArkivStatistisk ÅrbogGrønlands LandsbibliotekStore koncerter på stribeVandhund nummer 1.000.000Kommuneqarfik Sermersooq – MalikForsidenVenskabsbyerLyngby-Taarbæk i GrønlandArctic Business NetworkWinter Cities 2008 i NuukDagligt opdaterede satellitbilleder fra NuukområdetKommuneqarfik Sermersooqs hjemmesideTurist i NuukGrønlands Statistiks databankGrønlands Hjemmestyres valgresultaterrrWorldCat124325457671310-5