def evaluations(ty, pv, useScipy = True): """ evaluations(ty, pv, useScipy) -> (ACC, MSE, SCC) ty, pv: list, tuple or ndarray useScipy: convert ty, pv to ndarray, and use scipy functions for the evaluation Calculate accuracy, mean squared error and squared correlation coefficient using the true values (ty) and predicted values (pv). """ if scipy != None and useScipy: return evaluations_scipy(scipy.asarray(ty), scipy.asarray(pv)) if len(ty) != len(pv): raise ValueError("len(ty) must be equal to len(pv)") total_correct = total_error = 0 sumv = sumy = sumvv = sumyy = sumvy = 0 for v, y in zip(pv, ty): if y == v: total_correct += 1 total_error += (v-y)*(v-y) sumv += v sumy += y sumvv += v*v sumyy += y*y sumvy += v*y l = len(ty) ACC = 100.0*total_correct/l MSE = total_error/l try: SCC = ((l*sumvy-sumv*sumy)*(l*sumvy-sumv*sumy))/((l*sumvv-sumv*sumv)*(l*sumyy-sumy*sumy)) except: SCC = float('nan') return (float(ACC), float(MSE), float(SCC))
def evaluations(ty, pv, useScipy=True): """ evaluations(ty, pv, useScipy) -> (ACC, MSE, SCC) ty, pv: list, tuple or ndarray useScipy: convert ty, pv to ndarray, and use scipy functions for the evaluation Calculate accuracy, mean squared error and squared correlation coefficient using the true values (ty) and predicted values (pv). """ if scipy != None and useScipy: return evaluations_scipy(scipy.asarray(ty), scipy.asarray(pv)) if len(ty) != len(pv): raise ValueError("len(ty) must be equal to len(pv)") total_correct = total_error = 0 sumv = sumy = sumvv = sumyy = sumvy = 0 for v, y in zip(pv, ty): if y == v: total_correct += 1 total_error += (v - y) * (v - y) sumv += v sumy += y sumvv += v * v sumyy += y * y sumvy += v * y l = len(ty) ACC = 100.0 * total_correct / l MSE = total_error / l try: SCC = ((l * sumvy - sumv * sumy) * (l * sumvy - sumv * sumy)) / ((l * sumvv - sumv * sumv) * (l * sumyy - sumy * sumy)) except: SCC = float('nan') return (float(ACC), float(MSE), float(SCC))