MCPcopy Index your code
hub / github.com/clips/pattern / evaluations

Function evaluations

pattern/vector/svm/libsvmutil.py:51–78  ·  view source on GitHub ↗

evaluations(ty, pv) -> (ACC, MSE, SCC) Calculate accuracy, mean squared error and squared correlation coefficient using the true values (ty) and predicted values (pv).

(ty, pv)

Source from the content-addressed store, hash-verified

49 libsvm.svm_save_model(model_file_name.encode(), model)
50
51def evaluations(ty, pv):
52 """
53 evaluations(ty, pv) -> (ACC, MSE, SCC)
54
55 Calculate accuracy, mean squared error and squared correlation coefficient
56 using the true values (ty) and predicted values (pv).
57 """
58 if len(ty) != len(pv):
59 raise ValueError("len(ty) must equal to len(pv)")
60 total_correct = total_error = 0
61 sumv = sumy = sumvv = sumyy = sumvy = 0
62 for v, y in zip(pv, ty):
63 if y == v:
64 total_correct += 1
65 total_error += (v-y)*(v-y)
66 sumv += v
67 sumy += y
68 sumvv += v*v
69 sumyy += y*y
70 sumvy += v*y
71 l = len(ty)
72 ACC = 100.0*total_correct/l
73 MSE = total_error/l
74 try:
75 SCC = ((l*sumvy-sumv*sumy)*(l*sumvy-sumv*sumy))/((l*sumvv-sumv*sumv)*(l*sumyy-sumy*sumy))
76 except:
77 SCC = float('nan')
78 return (ACC, MSE, SCC)
79
80def svm_train(arg1, arg2=None, arg3=None):
81 """

Callers 2

svm_trainFunction · 0.70
svm_predictFunction · 0.70

Calls 2

lenFunction · 0.85
zipFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…