0
$\begingroup$

I am trying to print a accuracy score and get this message:

<function accuracy_score at 0x0000018A76046840>

So I am wondering if I am missing a package or is something installed incorrect?

Code:

from sklearn import datasets
from sklearn.metrics import accuracy_score
from sklearn import svm
iris = datasets.load_iris()
X = iris.data
y= iris.target
#print (iris.keys)
print('**********')
#print (iris['feature names'])
print('**********')
#print (iris)
#print (iris['data'].shape,'legth: ',len(iris['target']))
clf = svm.SVC(gamma=0.001, C=100)
clf.fit(X,y)
y_hat=clf.predict(X)
accuracy_score(y, y_hat)
score = accuracy_score
print (score)
$\endgroup$
  • $\begingroup$ Please post the code $\endgroup$ – trollster Jan 30 '18 at 16:31
  • $\begingroup$ Not, here, in the question itself. Edit the question and add the code. $\endgroup$ – trollster Jan 30 '18 at 16:33
1
$\begingroup$

The reason is that you are printing the object of function. Instead call the function. Suppose the name of your function is func. You are doing something like

print(func)

instead try to call it by adding parenthesis.

print(func())
$\endgroup$
1
$\begingroup$

This is how it must be:

score = accuracy_score(y, y_hat)
print (score)

You assigned empty function to score.

Your entire code should now be:

from sklearn import datasets
from sklearn.metrics import accuracy_score
from sklearn import svm
iris = datasets.load_iris()
X = iris.data
y= iris.target
#print (iris.keys)
print('**********')
#print (iris['feature names'])
print('**********')
#print (iris)
#print (iris['data'].shape,'legth: ',len(iris['target']))
clf = svm.SVC(gamma=0.001, C=100)
clf.fit(X,y)
y_hat=clf.predict(X)

score = accuracy_score(y, y_hat)
print (score)
$\endgroup$
  • $\begingroup$ Worked perfect, thank you very much, sorry first question and should have read how to post code first! $\endgroup$ – Gregory Boyle Jan 30 '18 at 16:40
  • 1
    $\begingroup$ Don't forget mark question answered (tick on best answer). $\endgroup$ – mico Jan 30 '18 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.