{
  "id": 7671,
  "title": "Evaluation",
  "url": "/competitions/acquire-valued-shoppers-challenge/discussion/7671",
  "author_name": "",
  "post_date": "2014-04-11T23:16:03.290Z",
  "votes": null,
  "comment_count": 15,
  "views": 5726,
  "content": "<p>I understand evaluation is done via AUC. I am familiar with AUC when predictions are binary, but in this case predictions are probabilities. Just saying AUC is also a little vague&nbsp;definition, since I've seen (in the literature) at least two different set of measurements being used in the XY axes.</p>\n<p>Is it possible (for the sake of clarity) to provide the specific formula under which the evaluation is being done? I think many people will appreciate this.</p>\n<p>Many thanks in advance,</p>",
  "messages": [
    {
      "id": "41767",
      "postDate": "04/11/2014 23:16:03",
      "content": "<p>I understand evaluation is done via AUC. I am familiar with AUC when predictions are binary, but in this case predictions are probabilities. Just saying AUC is also a little vague&nbsp;definition, since I've seen (in the literature) at least two different set of measurements being used in the XY axes.</p>\n<p>Is it possible (for the sake of clarity) to provide the specific formula under which the evaluation is being done? I think many people will appreciate this.</p>\n<p>Many thanks in advance,</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41770",
      "postDate": "04/12/2014 00:19:22",
      "content": "<p>Not sure what you mean by that. It's Area under the ROC Curve. Which is meant to be probabilities since it tries to evaluate a classifier as its discrimination threshold is varied so using that metric to evaluate binary predictions defeat the purpose of using the metric in the first place [1].</p>\n<p>Can you elaborate on the 2 or more Area under the ROC Curve measurement you're referring to?</p>\n<p>Regardless here's some&nbsp;R code/formula to what kaggle is referring to:</p>\n<p>EDIT: It came out weird when I posted it, but you can look up the verification package in R's implementation.&nbsp;[2]</p>\n<p>Hope that helps.</p>\n<p>[1] http://en.wikipedia.org/wiki/Receiver_operating_characteristic</p>\n<p>[2] http://cran.r-project.org/web/packages/verification/verification.pdf</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41772",
      "postDate": "04/12/2014 01:13:13",
      "content": "<p>What I wanted to say (in short) is that every contest I've seen so far, explicitly states the formula for the evaluation. For instance, if prediction for sample i is y_i, and true value&nbsp;for sample i is&nbsp;t_i, then the &quot;evaluation&quot; page provides some&nbsp;specific formula that depends&nbsp;on y_i and t_i for i=1,...,#samples.</p>\n<p>I dont see this formula (or algorithm) for this contest. That's why I brought this to your attention. Are you guys using specifically &quot;roc.area&quot; in R, or following the reference in the file verification.pdf&nbsp;that you just sent me (Mason and Graham 2002)?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41784",
      "postDate": "04/12/2014 13:51:29",
      "content": "<p>I'm sorry, but I'm having trouble understanding your confusion. Can you elaborate on the other Area under the ROC&nbsp;curves you know of?</p>\n\n<p>I linked the roc.area function from the verification package because it was previously referenced by Kaggle on the amazon competition. That said, there's only one area under the ROC Curve that I know of so I don't think I can adequately respond without knowing what other metrics or differences you're referring to. The comment about using Area under the ROC Curve to evaluate binary predictions is a bit confusing too&nbsp;since it defeats the purpose of the metric I am referring to.&nbsp;As far as I know, the pdf referencing the metric I sent you, &nbsp;the implementations in R, and every other &quot;area under the ROC&quot; are the same thing so I'm a bit confused by what&nbsp;you're differentiating.</p>\n\n<p>If it helps, here are some other references for the exact metric.:</p>\n\n<p>[1]&nbsp;http://gim.unmc.edu/dxtests/roc3.htm</p>\n<p>[2]&nbsp;https://www.kaggle.com/wiki/AreaUnderCurve</p>\n\n<p>Good luck! Sorry I couldn't help much.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41786",
      "postDate": "04/12/2014 14:35:14",
      "content": "<p>Suppose that we have x (binary) and y (continuous) values.</p>\n<p>y is sorted, and accordingly, x also.</p>\n<p>Using the first value of y (sorted) as a threshold, sensitivity and specificity are calculated.</p>\n<p>Again, with the second value of y as a threshold, until the last value of y....</p>\n<p>Now we can draw a roc curve.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41916",
      "postDate": "04/15/2014 06:57:40",
      "content": "<p>Hi all,&nbsp;</p>\n<p>Did you manage yet to reproduce your score on the public board with a independent testsample of the training data?&nbsp;</p>\n<p>I am struggling with this. To make sure its not just due to a fluctuation in the testsample used for online evaluation I split my private testsample into junks of the same size but found variations in the AUC of about 1%... definitely much lower than the ~15% difference I observe with respect to the online score.&nbsp;</p>\n<p>My ROC curve follows in principle the explanation of Jung with one difference being that I use to bin my samples into equidistant parts.. lets say p ordered in 50 bins between 0-1.&nbsp;</p>\n<p>Cheers,</p>\n<p>TT</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41977",
      "postDate": "04/15/2014 22:56:15",
      "content": "<p>[quote=Tautau;41916]</p>\n<p>Hi all,&nbsp;</p>\n<p>Did you manage yet to reproduce your score on the public board with a independent testsample of the training data?&nbsp;</p>\n<p>I am struggling with this.</p>\n<p>[/quote]</p>\n<p>Me too. I think it is due to noise or outliers. Have you tried removing outliers from your train set or tried normalization by any other means?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42002",
      "postDate": "04/16/2014 05:34:51",
      "content": "<p>Hi Triskelion,&nbsp;</p>\n\n<p>thanks for your answer.&nbsp;</p>\n<p>I don't think that outliers in the part of trainingdata I use for evaluation are a problem since the ROC ruve is astonishing smooth. But you might be right when it comes to the online test sample.&nbsp;</p>\n<p>I should try reducing the size of the evaluation dataset until I see large fluctuation appearing.&nbsp;</p>\n\n<p>There is also a second thread about this, so it seems we are not the only ones..&nbsp;</p>\n<p>Thanks!</p>\n<p>TT</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42033",
      "postDate": "04/16/2014 13:33:40",
      "content": "<p>[quote=Tautau;42002]</p>\n<p>There is also a second thread about this, so it seems we are not the only ones.</p>\n<p>Thanks!</p>\n<p>TT</p>\n<p>[/quote]</p>\n\n<p>You are not the only ones! &nbsp;I think the issue is that the test set is actually very different from the train set. &nbsp;There are lots of&nbsp;chains, categories, companies, and brands in the test set that are not present in the training set. It's hard to make your own validation set with a similar split.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42041",
      "postDate": "04/16/2014 14:05:03",
      "content": "<p>[quote=Triskelion;41977]</p>\n<p>[quote=Tautau;41916]</p>\n<p>Hi all,&nbsp;</p>\n<p>Did you manage yet to reproduce your score on the public board with a independent testsample of the training data?&nbsp;</p>\n<p>I am struggling with this.</p>\n<p>[/quote]</p>\n<p>Me too. I think it is due to noise or outliers. Have you tried removing outliers from your train set or tried normalization by any other means?</p>\n<p>[/quote]</p>\n<p>I gave this competition a shot and got a random sampled CV score of .66 AUC and I knew something was wrong because top kagglers would have easily beaten it so I made some submissions&nbsp;yesterday. It confirmed my suspicion something was wrong when I got .503 AUC. I figured it was due to temporal distortions and when I split the training set to March and CV set to April, my AUC dropped to .53. I did a few more tests with the leaderboard and it seemed to match my hypothesis&nbsp;that it's mainly due to temporal issues, especially considering the fact that the training set is March-April and test set is the months afterwards. When I focused only on the single offervalue variable, the LB AUC slightly increased&nbsp;after dropping the market and brand variables.</p>\n<p>It makes sense since company success&nbsp;and brand success&nbsp;has shown correlation with sales, but not much causation (at least according to my last semester marketing professor, lol). The split based on temporal lines would force one to find variables with actual causation.</p>\n<p>EDIT: Also note that March/April CV split isn't that good either since the months in the test set are further apart from the training set.</p>\n<p>EDIT2: Actually, I think it's better to say <strong>a random CV split causes leakage and the temporal train/test split prevents it.&nbsp;</strong>Making a good CV set will be a challenge.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42046",
      "postDate": "04/16/2014 14:45:21",
      "content": "<p>Good catch!&nbsp;</p>\n<p>We are looking at a time dependence one might wanna try to use in some smart way.. Lets try this ; )</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42049",
      "postDate": "04/16/2014 14:53:06",
      "content": "<p>Leave AUC aloneee....</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42199",
      "postDate": "04/17/2014 13:10:53",
      "content": "<p>I'm also finding that my public leaderboard scores come out lower than my CV scores. &nbsp;My best leaderboard score is currently a non-learning solution. &nbsp;It was simply an attempt to build a &quot;improved benchmark.&quot; &nbsp;It is about 4 lines of code using some of the features that others have described in other forum topics.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42258",
      "postDate": "04/17/2014 20:41:06",
      "content": "<p>Getting validation right is a challenge in itself in this competition. I think it has to do with test offers being mostly absent from the training set.</p>\n<p><code>import pandas as pd</code></p>\n<p><code>train = pd.read_csv( train_file )<br>test = pd.read_csv( test_file )</code></p>\n<p><code>for col in ( 'offer', 'chain', 'market', 'id' ):<br>&nbsp; &nbsp; print &quot;train in test:&quot;, col, sum( train[col].isin( test[col] ))<br>&nbsp; &nbsp; print &quot;test in train:&quot;, col, sum( test[col].isin( train[col] ))<br> <br><br>train in test: offer 71672<br>test in train: offer 5568<br>train in test: chain 159966<br>test in train: chain 151183<br>train in test: market 160057<br>test in train: market 151484<br>train in test: id 0<br>test in train: id 0<br><br></code></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42263",
      "postDate": "04/17/2014 21:33:42",
      "content": "<p>I'm a total newbie at ROC and AUC, so, I apologize in advance, but here's what I'd like: I'm pretty sure that the evaluation method takes as input two vectors, one with predicted values and one with the observed values, both ordered by customer, and calculates a single number, and I'm pretty sure that there's an algorithm for that. I would find it very helpful to have someone provide&nbsp;that algorithm, exactly, preferable written in standard mathematical notation. (Yes, I know, someone published a link to some C++ code, which may or may not be the algorithm used in this contest, but&nbsp;I would prefer not to have to learn yet another language just to figure out&nbsp;the evaluation method.)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42277",
      "postDate": "04/18/2014 02:11:49",
      "content": "<p>[quote=rks13;42263]</p>\n<p>...&nbsp;I would find it very helpful to have someone provide that algorithm, exactly, preferable written in standard mathematical notation ...</p>\n<p>[/quote]</p>\n<p>If you use python see: <a href=\"http://scikit-learn.org/stable/modules/model_evaluation.html\">sklearn model evaluation</a>&nbsp;and <a href=\"http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html#sklearn.metrics.roc_auc_score\">sklearn.metrics.roc_auc_score</a>:</p>\n<p><code>import numpy as np<br>from sklearn.metrics import roc_auc_score<br>y_true = np.array([0, 0, 1, 1])<br>y_scores = np.array([0.1, 0.4, 0.35, 0.8])<br>score = roc_auc_score(y_true, y_scores)<br>print score #&nbsp;0.75</code></p>\n<p>If you use Matlab:</p>\n<p><code>[X,Y,T,AUC] = perfcurve(class,y_pred,posclass);</code></p>\n<p>For algorithmic C# code see&nbsp;<a href=\"https://www.kaggle.com/c/SemiSupervisedFeatureLearning/forums/t/919/auc-implementation/6136#post6136\">this post</a>. That may be the code in use at Kaggle.</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 41770,
      "author_name": "duffman",
      "author_url": "",
      "post_date": "04/12/2014 00:19:22",
      "content": "<p>Not sure what you mean by that. It's Area under the ROC Curve. Which is meant to be probabilities since it tries to evaluate a classifier as its discrimination threshold is varied so using that metric to evaluate binary predictions defeat the purpose of using the metric in the first place [1].</p>\n<p>Can you elaborate on the 2 or more Area under the ROC Curve measurement you're referring to?</p>\n<p>Regardless here's some&nbsp;R code/formula to what kaggle is referring to:</p>\n<p>EDIT: It came out weird when I posted it, but you can look up the verification package in R's implementation.&nbsp;[2]</p>\n<p>Hope that helps.</p>\n<p>[1] http://en.wikipedia.org/wiki/Receiver_operating_characteristic</p>\n<p>[2] http://cran.r-project.org/web/packages/verification/verification.pdf</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41772,
      "author_name": "somniumvenator",
      "author_url": "",
      "post_date": "04/12/2014 01:13:13",
      "content": "<p>What I wanted to say (in short) is that every contest I've seen so far, explicitly states the formula for the evaluation. For instance, if prediction for sample i is y_i, and true value&nbsp;for sample i is&nbsp;t_i, then the &quot;evaluation&quot; page provides some&nbsp;specific formula that depends&nbsp;on y_i and t_i for i=1,...,#samples.</p>\n<p>I dont see this formula (or algorithm) for this contest. That's why I brought this to your attention. Are you guys using specifically &quot;roc.area&quot; in R, or following the reference in the file verification.pdf&nbsp;that you just sent me (Mason and Graham 2002)?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41784,
      "author_name": "duffman",
      "author_url": "",
      "post_date": "04/12/2014 13:51:29",
      "content": "<p>I'm sorry, but I'm having trouble understanding your confusion. Can you elaborate on the other Area under the ROC&nbsp;curves you know of?</p>\n\n<p>I linked the roc.area function from the verification package because it was previously referenced by Kaggle on the amazon competition. That said, there's only one area under the ROC Curve that I know of so I don't think I can adequately respond without knowing what other metrics or differences you're referring to. The comment about using Area under the ROC Curve to evaluate binary predictions is a bit confusing too&nbsp;since it defeats the purpose of the metric I am referring to.&nbsp;As far as I know, the pdf referencing the metric I sent you, &nbsp;the implementations in R, and every other &quot;area under the ROC&quot; are the same thing so I'm a bit confused by what&nbsp;you're differentiating.</p>\n\n<p>If it helps, here are some other references for the exact metric.:</p>\n\n<p>[1]&nbsp;http://gim.unmc.edu/dxtests/roc3.htm</p>\n<p>[2]&nbsp;https://www.kaggle.com/wiki/AreaUnderCurve</p>\n\n<p>Good luck! Sorry I couldn't help much.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41786,
      "author_name": "jung299056",
      "author_url": "",
      "post_date": "04/12/2014 14:35:14",
      "content": "<p>Suppose that we have x (binary) and y (continuous) values.</p>\n<p>y is sorted, and accordingly, x also.</p>\n<p>Using the first value of y (sorted) as a threshold, sensitivity and specificity are calculated.</p>\n<p>Again, with the second value of y as a threshold, until the last value of y....</p>\n<p>Now we can draw a roc curve.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41916,
      "author_name": "waldi32",
      "author_url": "",
      "post_date": "04/15/2014 06:57:40",
      "content": "<p>Hi all,&nbsp;</p>\n<p>Did you manage yet to reproduce your score on the public board with a independent testsample of the training data?&nbsp;</p>\n<p>I am struggling with this. To make sure its not just due to a fluctuation in the testsample used for online evaluation I split my private testsample into junks of the same size but found variations in the AUC of about 1%... definitely much lower than the ~15% difference I observe with respect to the online score.&nbsp;</p>\n<p>My ROC curve follows in principle the explanation of Jung with one difference being that I use to bin my samples into equidistant parts.. lets say p ordered in 50 bins between 0-1.&nbsp;</p>\n<p>Cheers,</p>\n<p>TT</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41977,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "04/15/2014 22:56:15",
      "content": "<p>[quote=Tautau;41916]</p>\n<p>Hi all,&nbsp;</p>\n<p>Did you manage yet to reproduce your score on the public board with a independent testsample of the training data?&nbsp;</p>\n<p>I am struggling with this.</p>\n<p>[/quote]</p>\n<p>Me too. I think it is due to noise or outliers. Have you tried removing outliers from your train set or tried normalization by any other means?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42002,
      "author_name": "waldi32",
      "author_url": "",
      "post_date": "04/16/2014 05:34:51",
      "content": "<p>Hi Triskelion,&nbsp;</p>\n\n<p>thanks for your answer.&nbsp;</p>\n<p>I don't think that outliers in the part of trainingdata I use for evaluation are a problem since the ROC ruve is astonishing smooth. But you might be right when it comes to the online test sample.&nbsp;</p>\n<p>I should try reducing the size of the evaluation dataset until I see large fluctuation appearing.&nbsp;</p>\n\n<p>There is also a second thread about this, so it seems we are not the only ones..&nbsp;</p>\n<p>Thanks!</p>\n<p>TT</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42033,
      "author_name": "zachmayer",
      "author_url": "",
      "post_date": "04/16/2014 13:33:40",
      "content": "<p>[quote=Tautau;42002]</p>\n<p>There is also a second thread about this, so it seems we are not the only ones.</p>\n<p>Thanks!</p>\n<p>TT</p>\n<p>[/quote]</p>\n\n<p>You are not the only ones! &nbsp;I think the issue is that the test set is actually very different from the train set. &nbsp;There are lots of&nbsp;chains, categories, companies, and brands in the test set that are not present in the training set. It's hard to make your own validation set with a similar split.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42041,
      "author_name": "duffman",
      "author_url": "",
      "post_date": "04/16/2014 14:05:03",
      "content": "<p>[quote=Triskelion;41977]</p>\n<p>[quote=Tautau;41916]</p>\n<p>Hi all,&nbsp;</p>\n<p>Did you manage yet to reproduce your score on the public board with a independent testsample of the training data?&nbsp;</p>\n<p>I am struggling with this.</p>\n<p>[/quote]</p>\n<p>Me too. I think it is due to noise or outliers. Have you tried removing outliers from your train set or tried normalization by any other means?</p>\n<p>[/quote]</p>\n<p>I gave this competition a shot and got a random sampled CV score of .66 AUC and I knew something was wrong because top kagglers would have easily beaten it so I made some submissions&nbsp;yesterday. It confirmed my suspicion something was wrong when I got .503 AUC. I figured it was due to temporal distortions and when I split the training set to March and CV set to April, my AUC dropped to .53. I did a few more tests with the leaderboard and it seemed to match my hypothesis&nbsp;that it's mainly due to temporal issues, especially considering the fact that the training set is March-April and test set is the months afterwards. When I focused only on the single offervalue variable, the LB AUC slightly increased&nbsp;after dropping the market and brand variables.</p>\n<p>It makes sense since company success&nbsp;and brand success&nbsp;has shown correlation with sales, but not much causation (at least according to my last semester marketing professor, lol). The split based on temporal lines would force one to find variables with actual causation.</p>\n<p>EDIT: Also note that March/April CV split isn't that good either since the months in the test set are further apart from the training set.</p>\n<p>EDIT2: Actually, I think it's better to say <strong>a random CV split causes leakage and the temporal train/test split prevents it.&nbsp;</strong>Making a good CV set will be a challenge.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42046,
      "author_name": "waldi32",
      "author_url": "",
      "post_date": "04/16/2014 14:45:21",
      "content": "<p>Good catch!&nbsp;</p>\n<p>We are looking at a time dependence one might wanna try to use in some smart way.. Lets try this ; )</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42049,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "04/16/2014 14:53:06",
      "content": "<p>Leave AUC aloneee....</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42199,
      "author_name": "breakfastpirate",
      "author_url": "",
      "post_date": "04/17/2014 13:10:53",
      "content": "<p>I'm also finding that my public leaderboard scores come out lower than my CV scores. &nbsp;My best leaderboard score is currently a non-learning solution. &nbsp;It was simply an attempt to build a &quot;improved benchmark.&quot; &nbsp;It is about 4 lines of code using some of the features that others have described in other forum topics.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42258,
      "author_name": "zygmunt",
      "author_url": "",
      "post_date": "04/17/2014 20:41:06",
      "content": "<p>Getting validation right is a challenge in itself in this competition. I think it has to do with test offers being mostly absent from the training set.</p>\n<p><code>import pandas as pd</code></p>\n<p><code>train = pd.read_csv( train_file )<br>test = pd.read_csv( test_file )</code></p>\n<p><code>for col in ( 'offer', 'chain', 'market', 'id' ):<br>&nbsp; &nbsp; print &quot;train in test:&quot;, col, sum( train[col].isin( test[col] ))<br>&nbsp; &nbsp; print &quot;test in train:&quot;, col, sum( test[col].isin( train[col] ))<br> <br><br>train in test: offer 71672<br>test in train: offer 5568<br>train in test: chain 159966<br>test in train: chain 151183<br>train in test: market 160057<br>test in train: market 151484<br>train in test: id 0<br>test in train: id 0<br><br></code></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42263,
      "author_name": "rks138062",
      "author_url": "",
      "post_date": "04/17/2014 21:33:42",
      "content": "<p>I'm a total newbie at ROC and AUC, so, I apologize in advance, but here's what I'd like: I'm pretty sure that the evaluation method takes as input two vectors, one with predicted values and one with the observed values, both ordered by customer, and calculates a single number, and I'm pretty sure that there's an algorithm for that. I would find it very helpful to have someone provide&nbsp;that algorithm, exactly, preferable written in standard mathematical notation. (Yes, I know, someone published a link to some C++ code, which may or may not be the algorithm used in this contest, but&nbsp;I would prefer not to have to learn yet another language just to figure out&nbsp;the evaluation method.)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42277,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "04/18/2014 02:11:49",
      "content": "<p>[quote=rks13;42263]</p>\n<p>...&nbsp;I would find it very helpful to have someone provide that algorithm, exactly, preferable written in standard mathematical notation ...</p>\n<p>[/quote]</p>\n<p>If you use python see: <a href=\"http://scikit-learn.org/stable/modules/model_evaluation.html\">sklearn model evaluation</a>&nbsp;and <a href=\"http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html#sklearn.metrics.roc_auc_score\">sklearn.metrics.roc_auc_score</a>:</p>\n<p><code>import numpy as np<br>from sklearn.metrics import roc_auc_score<br>y_true = np.array([0, 0, 1, 1])<br>y_scores = np.array([0.1, 0.4, 0.35, 0.8])<br>score = roc_auc_score(y_true, y_scores)<br>print score #&nbsp;0.75</code></p>\n<p>If you use Matlab:</p>\n<p><code>[X,Y,T,AUC] = perfcurve(class,y_pred,posclass);</code></p>\n<p>For algorithmic C# code see&nbsp;<a href=\"https://www.kaggle.com/c/SemiSupervisedFeatureLearning/forums/t/919/auc-implementation/6136#post6136\">this post</a>. That may be the code in use at Kaggle.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "41767": "",
    "41770": "",
    "41772": "",
    "41784": "",
    "41786": "",
    "41916": "",
    "41977": "",
    "42002": "",
    "42033": "",
    "42041": "",
    "42046": "",
    "42049": "",
    "42199": "",
    "42258": "",
    "42263": "",
    "42277": ""
  },
  "source": "meta"
}