def run(tday, history, logfile): logstr = '' # w, x, y = history.grab(nsample, ntracks, tday + 1) x = xfilter(x) timer = timer_c() lsvm = svmutil.svm_train(y, x, options) #svmutil.svm_save_model('benchmark.svm', lsvm) #lsvm = svmutil.svm_load_model('benchmark.svm') print 'svm trained successfully in %s sec.' % (str( float('{0:.3f}'.format(timer.lag())))) # timer = timer_c() p_labels, p_acc, p_vals = svmutil.svm_predict(y, x, lsvm, '') print 'svm predicted successfully in %s sec.' % (str( float('{0:.3f}'.format(timer.lag())))) plotdraw(p_labels, y) # timer = timer_c() w, x, y = history.grab(1, ntracks, tday) x = xfilter(x) p_labels, p_acc, p_vals = svmutil.svm_predict(y, x, lsvm, '') print 'svm predicted successfully in %s sec.' % (str( float('{0:.3f}'.format(timer.lag())))) plotdraw(p_labels, y)
def run(history): # w, x, y = history.grab(nsample, ntracks, 0) timer = timer_c() lsvm = svmutil.svm_train(y, x, options) svmutil.svm_save_model('temp.svm', lsvm) print 'svm trained successfully in %s sec.' % (str(float('{0:.3f}'.format(timer.lag())))) # timer = timer_c() p_labels, p_acc, p_vals = svmutil.svm_predict(y, x, lsvm, '') print 'svm predicted successfully in %s sec.' % (str(float('{0:.3f}'.format(timer.lag())))) plotdraw(p_labels, y)
def run(history, tweek, pref): # timer = timer_c() lsvm = svmutil.svm_load_model('temp.svm') print 'svm loaded successfully in %s sec.' % (str(float('{0:.3f}'.format(timer.lag())))) # w, x, y = history.grab(1, ntracks, tweek-1, pref) x = xfilter(x) timer.reset() p_labels, p_acc, p_vals = svmutil.svm_predict(y, x, lsvm, '') print 'svm predicted successfully in %s sec with %d samples.' % (str(float('{0:.3f}'.format(timer.lag()))), len(w)) plotdraw(p_labels, y) # foo = [] for i in xrange(len(w)): foo.append((w[i], p_labels[i], y[i])) foo.sort(key = lambda tup: (tup[1])) for row in foo: print '%s y\' = %.6f, y = %.6f' % row