Skip to content

Commit 4dd56d6

Browse files
authored
Merge branch 'master' into modernize-python2-code
2 parents e23cab5 + d8bd5f1 commit 4dd56d6

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

AnomalyDetection/AnomalyDetection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def anomalyDetection_example():
1616
plt.show()
1717
'''多元高斯分布函数,并可视化拟合的边界'''
1818
mu,sigma2 = estimateGaussian(X) # 参数估计(求均值和方差)
19-
#print mu,sigma2
19+
#print (mu,sigma2)
2020
p = multivariateGaussian(X,mu,sigma2) # 多元高斯分布函数
21-
#print p
21+
#print (p)
2222
visualizeFit(X,mu,sigma2) # 显示图像
2323

2424
'''选择异常点(在交叉验证CV上训练得到最好的epsilon)'''
@@ -73,7 +73,7 @@ def visualizeFit(X,mu,sigma2):
7373
plt.plot(X[:,0],X[:,1],'bx')
7474

7575
if np.sum(np.isinf(Z).astype(float)) == 0: # 如果计算的为无穷,就不用画了
76-
# plt.contourf(X1,X2,Z,10.**np.arange(-20, 0, 3),linewidth=.5)
76+
#plt.contourf(X1,X2,Z,10.**np.arange(-20, 0, 3),linewidth=.5)
7777
CS = plt.contour(X1,X2,Z,10.**np.arange(-20, 0, 3),color='black',linewidth=.5) # 画等高线,Z的值在10.**np.arange(-20, 0, 3)
7878
#plt.clabel(CS)
7979

@@ -89,9 +89,9 @@ def selectThreshold(yval,pval):
8989
'''计算'''
9090
for epsilon in np.arange(np.min(pval),np.max(pval),step):
9191
cvPrecision = pval<epsilon
92-
tp = np.sum((cvPrecision == 1) & (yval == 1)).astype(float) # sum求和是int型的,需要转为float
93-
fp = np.sum((cvPrecision == 1) & (yval == 0)).astype(float)
94-
fn = np.sum((cvPrecision == 1) & (yval == 0)).astype(float)
92+
tp = np.sum((cvPrecision == 1) & (yval == 1).ravel()).astype(float) # sum求和是int型的,需要转为float
93+
fp = np.sum((cvPrecision == 1) & (yval == 0).ravel()).astype(float)
94+
fn = np.sum((cvPrecision == 0) & (yval == 1).ravel()).astype(float)
9595
precision = tp/(tp+fp) # 精准度
9696
recision = tp/(tp+fn) # 召回率
9797
F1 = (2*precision*recision)/(precision+recision) # F1Score计算公式

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,9 @@ def selectThreshold(yval,pval):
11611161
'''计算'''
11621162
for epsilon in np.arange(np.min(pval),np.max(pval),step):
11631163
cvPrecision = pval<epsilon
1164-
tp = np.sum((cvPrecision == 1) & (yval == 1)).astype(float) # sum求和是int型的,需要转为float
1165-
fp = np.sum((cvPrecision == 1) & (yval == 0)).astype(float)
1166-
fn = np.sum((cvPrecision == 1) & (yval == 0)).astype(float)
1164+
tp = np.sum((cvPrecision == 1) & (yval == 1).ravel()).astype(float) # sum求和是int型的,需要转为float
1165+
fp = np.sum((cvPrecision == 1) & (yval == 0).ravel()).astype(float)
1166+
fn = np.sum((cvPrecision == 0) & (yval == 1).ravel()).astype(float)
11671167
precision = tp/(tp+fp) # 精准度
11681168
recision = tp/(tp+fn) # 召回率
11691169
F1 = (2*precision*recision)/(precision+recision) # F1Score计算公式

0 commit comments

Comments
 (0)