Python predict_proba












0















I have a question on a classification problem in machine learning using the log_loss function in scikit learn.



from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier()
classifier.fit(Xtrain, ytrain)
soft = classifier.predict_proba(Xtest)[:,1]
log_loss = log_loss(ytest, soft)


I would to compute the log loss but an error appears :



'numpy.float64' object is not callable


I think that this problem may come from the fact that there is some 0 in the vector soft. But I do know to solve this problem ?



s = 0
for x in soft :
if x == 0 :
s+=1
print(s)
>> 17729


Thanks in advance










share|improve this question























  • Show the full stack trace of error and how log_loss is imported?

    – Vivek Kumar
    Nov 14 '18 at 12:39
















0















I have a question on a classification problem in machine learning using the log_loss function in scikit learn.



from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier()
classifier.fit(Xtrain, ytrain)
soft = classifier.predict_proba(Xtest)[:,1]
log_loss = log_loss(ytest, soft)


I would to compute the log loss but an error appears :



'numpy.float64' object is not callable


I think that this problem may come from the fact that there is some 0 in the vector soft. But I do know to solve this problem ?



s = 0
for x in soft :
if x == 0 :
s+=1
print(s)
>> 17729


Thanks in advance










share|improve this question























  • Show the full stack trace of error and how log_loss is imported?

    – Vivek Kumar
    Nov 14 '18 at 12:39














0












0








0








I have a question on a classification problem in machine learning using the log_loss function in scikit learn.



from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier()
classifier.fit(Xtrain, ytrain)
soft = classifier.predict_proba(Xtest)[:,1]
log_loss = log_loss(ytest, soft)


I would to compute the log loss but an error appears :



'numpy.float64' object is not callable


I think that this problem may come from the fact that there is some 0 in the vector soft. But I do know to solve this problem ?



s = 0
for x in soft :
if x == 0 :
s+=1
print(s)
>> 17729


Thanks in advance










share|improve this question














I have a question on a classification problem in machine learning using the log_loss function in scikit learn.



from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier()
classifier.fit(Xtrain, ytrain)
soft = classifier.predict_proba(Xtest)[:,1]
log_loss = log_loss(ytest, soft)


I would to compute the log loss but an error appears :



'numpy.float64' object is not callable


I think that this problem may come from the fact that there is some 0 in the vector soft. But I do know to solve this problem ?



s = 0
for x in soft :
if x == 0 :
s+=1
print(s)
>> 17729


Thanks in advance







python-3.x machine-learning scikit-learn






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 11:46









user10651723user10651723

51




51













  • Show the full stack trace of error and how log_loss is imported?

    – Vivek Kumar
    Nov 14 '18 at 12:39



















  • Show the full stack trace of error and how log_loss is imported?

    – Vivek Kumar
    Nov 14 '18 at 12:39

















Show the full stack trace of error and how log_loss is imported?

– Vivek Kumar
Nov 14 '18 at 12:39





Show the full stack trace of error and how log_loss is imported?

– Vivek Kumar
Nov 14 '18 at 12:39












1 Answer
1






active

oldest

votes


















-1














It appears as if your issue here is not really with the log_loss inputs, but just to do with your variable naming. Everything in python is an object and so in the line:



log_loss = log_loss(ytest, soft)


you assigned the answer, a number (of type numpy.float64), to the token log_loss. So your variable shadows the function. Then, subsequent calls, as if it were a function, fail.



from sklearn.metrics import log_loss
print(log_loss)
>>> <function log_loss at 0x7f9f692db1b8>

log_loss = log_loss(ytest, soft)
print(log_loss)
>>> 0.11895972559889094
log_loss = log_loss(ytest, soft)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-b423b2324b92> in <module>()
----> 1 log_loss = log_loss(ytest, soft)

TypeError: 'numpy.float64' object is not callable


Simplest resolution is not to call your variable log_loss, but more generally you might find some level of namespacing helps, e.g. instead of



from sklearn.metrics import log_loss
...
loss = log_loss(ytest, soft)


you could use



from sklearn import metrics
...
loss = metrics.log_loss(ytest, soft)





share|improve this answer
























  • Thanks a lot!!!

    – user10651723
    Nov 14 '18 at 15:05











  • thanks but downvote? is your problem solved or do you need further help to get there?

    – Bonlenfum
    Nov 15 '18 at 11:02













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53299509%2fpython-predict-proba%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









-1














It appears as if your issue here is not really with the log_loss inputs, but just to do with your variable naming. Everything in python is an object and so in the line:



log_loss = log_loss(ytest, soft)


you assigned the answer, a number (of type numpy.float64), to the token log_loss. So your variable shadows the function. Then, subsequent calls, as if it were a function, fail.



from sklearn.metrics import log_loss
print(log_loss)
>>> <function log_loss at 0x7f9f692db1b8>

log_loss = log_loss(ytest, soft)
print(log_loss)
>>> 0.11895972559889094
log_loss = log_loss(ytest, soft)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-b423b2324b92> in <module>()
----> 1 log_loss = log_loss(ytest, soft)

TypeError: 'numpy.float64' object is not callable


Simplest resolution is not to call your variable log_loss, but more generally you might find some level of namespacing helps, e.g. instead of



from sklearn.metrics import log_loss
...
loss = log_loss(ytest, soft)


you could use



from sklearn import metrics
...
loss = metrics.log_loss(ytest, soft)





share|improve this answer
























  • Thanks a lot!!!

    – user10651723
    Nov 14 '18 at 15:05











  • thanks but downvote? is your problem solved or do you need further help to get there?

    – Bonlenfum
    Nov 15 '18 at 11:02


















-1














It appears as if your issue here is not really with the log_loss inputs, but just to do with your variable naming. Everything in python is an object and so in the line:



log_loss = log_loss(ytest, soft)


you assigned the answer, a number (of type numpy.float64), to the token log_loss. So your variable shadows the function. Then, subsequent calls, as if it were a function, fail.



from sklearn.metrics import log_loss
print(log_loss)
>>> <function log_loss at 0x7f9f692db1b8>

log_loss = log_loss(ytest, soft)
print(log_loss)
>>> 0.11895972559889094
log_loss = log_loss(ytest, soft)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-b423b2324b92> in <module>()
----> 1 log_loss = log_loss(ytest, soft)

TypeError: 'numpy.float64' object is not callable


Simplest resolution is not to call your variable log_loss, but more generally you might find some level of namespacing helps, e.g. instead of



from sklearn.metrics import log_loss
...
loss = log_loss(ytest, soft)


you could use



from sklearn import metrics
...
loss = metrics.log_loss(ytest, soft)





share|improve this answer
























  • Thanks a lot!!!

    – user10651723
    Nov 14 '18 at 15:05











  • thanks but downvote? is your problem solved or do you need further help to get there?

    – Bonlenfum
    Nov 15 '18 at 11:02
















-1












-1








-1







It appears as if your issue here is not really with the log_loss inputs, but just to do with your variable naming. Everything in python is an object and so in the line:



log_loss = log_loss(ytest, soft)


you assigned the answer, a number (of type numpy.float64), to the token log_loss. So your variable shadows the function. Then, subsequent calls, as if it were a function, fail.



from sklearn.metrics import log_loss
print(log_loss)
>>> <function log_loss at 0x7f9f692db1b8>

log_loss = log_loss(ytest, soft)
print(log_loss)
>>> 0.11895972559889094
log_loss = log_loss(ytest, soft)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-b423b2324b92> in <module>()
----> 1 log_loss = log_loss(ytest, soft)

TypeError: 'numpy.float64' object is not callable


Simplest resolution is not to call your variable log_loss, but more generally you might find some level of namespacing helps, e.g. instead of



from sklearn.metrics import log_loss
...
loss = log_loss(ytest, soft)


you could use



from sklearn import metrics
...
loss = metrics.log_loss(ytest, soft)





share|improve this answer













It appears as if your issue here is not really with the log_loss inputs, but just to do with your variable naming. Everything in python is an object and so in the line:



log_loss = log_loss(ytest, soft)


you assigned the answer, a number (of type numpy.float64), to the token log_loss. So your variable shadows the function. Then, subsequent calls, as if it were a function, fail.



from sklearn.metrics import log_loss
print(log_loss)
>>> <function log_loss at 0x7f9f692db1b8>

log_loss = log_loss(ytest, soft)
print(log_loss)
>>> 0.11895972559889094
log_loss = log_loss(ytest, soft)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-40-b423b2324b92> in <module>()
----> 1 log_loss = log_loss(ytest, soft)

TypeError: 'numpy.float64' object is not callable


Simplest resolution is not to call your variable log_loss, but more generally you might find some level of namespacing helps, e.g. instead of



from sklearn.metrics import log_loss
...
loss = log_loss(ytest, soft)


you could use



from sklearn import metrics
...
loss = metrics.log_loss(ytest, soft)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 12:47









BonlenfumBonlenfum

11.3k13142




11.3k13142













  • Thanks a lot!!!

    – user10651723
    Nov 14 '18 at 15:05











  • thanks but downvote? is your problem solved or do you need further help to get there?

    – Bonlenfum
    Nov 15 '18 at 11:02





















  • Thanks a lot!!!

    – user10651723
    Nov 14 '18 at 15:05











  • thanks but downvote? is your problem solved or do you need further help to get there?

    – Bonlenfum
    Nov 15 '18 at 11:02



















Thanks a lot!!!

– user10651723
Nov 14 '18 at 15:05





Thanks a lot!!!

– user10651723
Nov 14 '18 at 15:05













thanks but downvote? is your problem solved or do you need further help to get there?

– Bonlenfum
Nov 15 '18 at 11:02







thanks but downvote? is your problem solved or do you need further help to get there?

– Bonlenfum
Nov 15 '18 at 11:02




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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.


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%2fstackoverflow.com%2fquestions%2f53299509%2fpython-predict-proba%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

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python