ValueError: Data is not binary and pos_label is not specified

I am trying to calculate roc_auc_score, but I am getting following error.

"ValueError: Data is not binary and pos_label is not specified"

My code snippet is as follows:

import numpy as np
from sklearn.metrics import roc_auc_score
y_scores=np.array([ 0.63, 0.53, 0.36, 0.02, 0.70 ,1 , 0.48, 0.46, 0.57])
y_true=np.array(['0', '1', '0', '0', '1', '1', '1', '1', '1'])
roc_auc_score(y_true, y_scores)

Please tell me what is wrong with it.


You only need to change y_trueso it looks like this:

y_true=np.array([0, 1, 0, 0, 1, 1, 1, 1, 1])

Explanation: If you take a look to what roc_auc_score functions does in you will see that y_true is evaluated as follows:

classes = np.unique(y_true)
if (pos_label is None and not (np.all(classes == [0, 1]) or
 np.all(classes == [-1, 1]) or
 np.all(classes == [0]) or
 np.all(classes == [-1]) or
 np.all(classes == [1]))):
    raise ValueError("Data is not binary and pos_label is not specified")

At the moment of the execution pos_label is None, but as long as your are defining y_true as an array of characters the np.all are always false and as all of them are negated then the if condition is trueand the exception is raised.

Need Your Help

call the ' id ' of the mysql database with varchar format but Unknown column 'GE' in 'where clause'

php codeigniter codeigniter-2 codeigniter-url

I tried to call up data by 'id' format id example id = GE-DIS-001 to JOIN table with Codeigniter , the result of "Unknown column ' GE ' in 'where clause ' what's wrong ??

Information about widget context/lifecycle

java android android-widget

I've a widget that is packaged in an application and I've several doubts about the context/lifecycle of the widget/application:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.