mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-29 15:59:41 +02:00
replace np.int by int
This commit is contained in:
parent
a6d78d79aa
commit
65af6ee35e
15 changed files with 3889 additions and 2375 deletions
|
|
@ -2,7 +2,8 @@
|
|||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
import numpy as np
|
||||
|
||||
def conf_matrix(p,labels,names=['1','0'],threshold=.5,show=True):
|
||||
|
||||
def conf_matrix(p, labels, names=["1", "0"], threshold=0.5, show=True):
|
||||
"""
|
||||
Returns error rate and true/false positives in a binary classification problem
|
||||
- Actual classes are displayed by column.
|
||||
|
|
@ -16,18 +17,18 @@ def conf_matrix(p,labels,names=['1','0'],threshold=.5,show=True):
|
|||
:type show: False|True
|
||||
"""
|
||||
assert p.size == labels.size, "Arrays p and labels have different dimensions."
|
||||
decision = np.ones((labels.size,1))
|
||||
decision[p<threshold] = 0
|
||||
decision = np.ones((labels.size, 1))
|
||||
decision[p < threshold] = 0
|
||||
diff = decision - labels
|
||||
false_0 = diff[diff == -1].size
|
||||
false_1 = diff[diff == 1].size
|
||||
true_1 = np.sum(decision[diff ==0])
|
||||
true_1 = np.sum(decision[diff == 0])
|
||||
true_0 = labels.size - true_1 - false_0 - false_1
|
||||
error = (false_1 + false_0)/np.float(labels.size)
|
||||
error = (false_1 + false_0) / float(labels.size)
|
||||
if show:
|
||||
print(100. - error * 100,'% instances correctly classified')
|
||||
print('%-10s| %-10s| %-10s| ' % ('',names[0],names[1]))
|
||||
print('----------|------------|------------|')
|
||||
print('%-10s| %-10s| %-10s| ' % (names[0],true_1,false_0))
|
||||
print('%-10s| %-10s| %-10s| ' % (names[1],false_1,true_0))
|
||||
return error,true_1, false_1, true_0, false_0
|
||||
print(100.0 - error * 100, "% instances correctly classified")
|
||||
print("%-10s| %-10s| %-10s| " % ("", names[0], names[1]))
|
||||
print("----------|------------|------------|")
|
||||
print("%-10s| %-10s| %-10s| " % (names[0], true_1, false_0))
|
||||
print("%-10s| %-10s| %-10s| " % (names[1], false_1, true_0))
|
||||
return error, true_1, false_1, true_0, false_0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue