• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python svmutil.svm_predict函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中svmutil.svm_predict函数的典型用法代码示例。如果您正苦于以下问题:Python svm_predict函数的具体用法?Python svm_predict怎么用?Python svm_predict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了svm_predict函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test

 def test(self):
     count = 0
     d = 1
     for i in self.images:
         for j in i.testDataHist:
             ra = []
             la = []
             for l in range(len(self.mr)/2):#from the RBF models
                 a,b,c = svmutil.svm_predict([d],[j],self.mr[l*2],'-b 1')
                 ra.append(c)
             for l in range(len(self.ml)/2):#from the Linear models
                 a,b,c = svmutil.svm_predict([d],[j],self.ml[l*2],'-b 1')
                 la.append(c)
             self.hmr[count][ra.index(max(ra))]+=1#populating the confusion matricies
             self.hml[count][la.index(max(la))]+=1
         for k in i.testDataVector:
             ra = []
             la = []
             for l in range(len(self.mr)/2):#from the RBF models
                 a,b,c = svmutil.svm_predict([d],[k],self.mr[l*2+1],'-b 1')
                 ra.append(c)
             for l in range(len(self.ml)/2):#from the Linear models
                 a,b,c = svmutil.svm_predict([d],[k],self.ml[l*2+1],'-b 1')
                 la.append(c)
             self.vmr[count][ra.index(max(ra))]+=1
             self.vml[count][la.index(max(la))]+=1
         count+=1
         d = 0
开发者ID:virdesai,项目名称:Courses,代码行数:28,代码来源:HW4.py


示例2: TrainSvmLinear

def TrainSvmLinear(Y, X, sweep_c=range(-2,8)):
    num_positives = float(Y.count(1))
    num_negatives = float(Y.count(-1))

    best_c = -1
    best_acc = -1
    for c_pow in sweep_c:
        current_c = np.power(2.0,c_pow)
        prob = svm.svm_problem(Y,X)
        param = svm.svm_parameter('-v 5 -t 0 -c %f -w-1 %f -w1 %f -q' % (current_c,
                                                                         100/num_negatives,
                                                                         100/num_positives))
        current_acc = svm.svm_train(prob, param)
        print '%f, %f' % (current_c, current_acc)
        if best_acc < current_acc:
            best_acc = current_acc
            best_c = current_c

        # recompute accuracy
        param = svm.svm_parameter('-t 0 -c %f -w-1 %f -w1 %f -q' % (best_c,
                                                                    100/num_negatives,
                                                                    100/num_positives))
        svm_model = svm.svm_train(prob, param)
        p_labs, p_acc, p_vals = svm.svm_predict(Y, X, svm_model, '-q')


    prob = svm.svm_problem(Y,X)
    param = svm.svm_parameter('-t 0 -c %f -w-1 %f -w1 %f -q' % (best_c,
                                                                100/num_negatives,
                                                                100/num_positives))
    svm_model = svm.svm_train(prob, param)
    p_labs, p_acc, p_vals = svm.svm_predict(Y, X, svm_model, '-q')
    pdb.set_trace()
    return svm_model
开发者ID:CareShaw,项目名称:plex,代码行数:34,代码来源:svm_helpers.py


示例3: cons_train_sample_for_cla

def cons_train_sample_for_cla(filename,indexes,dic_path,glo_aff_path,result_save_path,model_path,LSA_path,LSA_model_path,decom_meas,delete):
    dic_list = read_dic(dic_path,dtype=str)
    glo_aff_list = read_list(glo_aff_path)
    f= file(filename,'r')
    fs = file(result_save_path,'w')
    fd = file(dust_save_path,'w')
    m= svm_load_model(model_path)
    lsa_m = svm_load_model(LSA_model_path)
    U = load_lsa_model(LSA_path,"U")
    for line in f.readlines():
        text = line.strip().split(tc_splitTag)
        if len(text)!=line_length:
            fd.write(line)
            continue
        text_temp=""
        for i in indexes:
            text_temp+=str_splitTag+text[i]  
        vec = cons_vec_for_cla(text_temp.strip().split(str_splitTag),dic_list,glo_aff_list)
        y,x=cons_svm_problem(text[0],vec)
        p_lab,p_acc,p_sc=svm_predict(y,x,m)
 
        if  decom_meas==1:
            weight = cal_weight(p_sc[0][0])
            #vec = [value*weight for value in vec ] 
            vec = [0]*len(vec)
            for key in x[0].keys():
               vec[int(key)-1]= weight*float(x[0][key])    
            vec = pre_doc_svds(vec,U)
            y,x=cons_svm_problem(text[0],vec)
            lsa_lab,lsa_acc,lsa_sc = svm_predict(y,x,lsa_m)
            fs.write(text[0]+"\t"+str(p_sc[0][0])+"\t"+str(lsa_sc[0][0])+"\t"+text[1]+"\t"+text[2]+"\n")
        else :
            fs.write(text[0]+"\t"+str(p_sc[0][0])+"\t"+text[1]+"\t"+text[2]+"\n")
    f.close()
    fs.close()
开发者ID:Kevin-yj-Zhao,项目名称:JunkFilter-for-MeiPai,代码行数:35,代码来源:post_check_lsa.py


示例4: test_model

def test_model(img_kind):
	subdir = "data/"
	model = svmutil.svm_load_model(subdir + img_kind + '.model')
	print "Finished Loading Model"

	total_count = 0
	correct_count = 0
	wrong_count = 0

	
	the_ones = glob.glob(subdir + "f_" + img_kind + "*.jpg")
	all_of_them = glob.glob(subdir + "f_*_*.jpg")
	the_others = []

	for x in all_of_them:
		total_count += 1
		if the_ones.count(x) < 1:
			the_others.append(x)
	
	for x in the_ones:
		img = cv.LoadImageM(x)
		cv.ShowImage("img", img)
		cv.WaitKey(10)
		img_features = get_image_features(img, True, img_kind)
		predict_input_data = []
		predict_input_data.append(img_features)
		(val, val_2, val_3) = svmutil.svm_predict([1], predict_input_data, model)
		if int(val[0]) == 1:
			print 'correct'
			correct_count += 1
		else:
			wrong_count += 1

	for x in the_others:
		img = cv.LoadImageM(x)
		cv.ShowImage("img", img)
		cv.WaitKey(10)
		img_features = get_image_features(img, True, img_kind)
		predict_input_data = []
		predict_input_data.append(img_features)
		(val, val_2, val_3) = svmutil.svm_predict([1], predict_input_data, model)
		if int(val[0]) == -1:
			correct_count += 1
		else:
			wrong_count += 1
	
	print "Total Pictures: " + str(total_count)
	print "Correct: " + str(correct_count)
	print "Wrong: " + str(wrong_count)
	print "Accuracy: " + str(correct_count/float(total_count) * 100) + '%'
开发者ID:prabhat1992,项目名称:emotion_recognition,代码行数:50,代码来源:utils+-+Copy.py


示例5: CrossValidate

def CrossValidate(Y, X, param, k_folds=5):
    rand_idx = range(len(Y))
    random.shuffle(rand_idx)
    idx_groups = SplitIntoK(k_folds, rand_idx)
    pos_acc = 0
    neg_acc = 0
    for i in range(k_folds):
        test_idx = idx_groups[i]
        exclude_test = [idx_groups[j] for j in range(len(idx_groups)) if i != j]
        train_idx = list(chain(*exclude_test))

        Y_test = [Y[test_i] for test_i in test_idx]
        X_test = [X[test_i] for test_i in test_idx]        

        Y_train = [Y[train_i] for train_i in train_idx]
        X_train = [X[train_i] for train_i in train_idx]        

        # recompute accuracy
        prob = svm.svm_problem(Y_train,X_train)
        svm_model = svm.svm_train(prob, param)

        p_labs, p_acc, p_vals = svm.svm_predict(Y_test, X_test, svm_model, '-q')

        tps = sum([1 for j in range(len(p_labs)) if (p_labs[j]==1 and Y_test[j]==1)])
        fns = sum([1 for j in range(len(p_labs)) if (p_labs[j]==-1 and Y_test[j]==1)])

        tns = sum([1 for j in range(len(p_labs)) if (p_labs[j]==-1 and Y_test[j]==-1)])
        fps = sum([1 for j in range(len(p_labs)) if (p_labs[j]==1 and Y_test[j]==-1)])

        pos_acc += tps / float(tps + fns)
        neg_acc += tns / float(tns + fps)

    pos_acc = pos_acc / k_folds
    neg_acc = neg_acc / k_folds
    return (pos_acc, neg_acc)
开发者ID:CareShaw,项目名称:plex,代码行数:35,代码来源:svm_helpers.py


示例6: predict

def predict(request):
    predictX = float( request.POST.get("x", -1) )
    predictY = float( request.POST.get("y", -1) )
    
    predictLabel = int( request.POST.get("label", -1) )
    
    if predictX == -1 or predictY == -1 or predictLabel == -1:
        return django.http.HttpResponse("Missing Params")
    
    points = models.Point2d.objects.all()
    
    # Storing the information to be presented to SVM
    labels = []
    inputs = []
    
    # For each point, store the information into arrays
    #for p in points:
    #    labels.append( p.label )
    #    inputs.append([p.x, p.y])
    
    #prob = svm.svm_problem(labels, inputs)
    #param = svm.svm_parameter('-t 2 -c 100')
    #model = svmutil.svm_train(prob, param)
    #svmutil.svm_save_model('libsvm.model', model)
    model = svmutil.svm_load_model('libsvm.model')
    
    p_label , acc, val = svmutil.svm_predict([0], [[predictX, predictY]], model)
   
    data = {'x': predictX, 'y': predictY, 'label': int( p_label[0] ) }
    return json(data)
开发者ID:ericmok,项目名称:eri53,代码行数:30,代码来源:ajax.py


示例7: classify

def classify(filename, classLabel=0):
    str = "/Thu_Life/CS/SVM/data/trainData/Test_SVMFile/singleSVM_TestFile"
    f = open(str, "wb")
    t = VSM.TextToVector2(filename)
    slabel = ("%d ") % classLabel
    if len(t) > 0:
        f.write(slabel)
        for k in range(len(t)):
            str1 = ("%d:%d ") % (t[k][0], t[k][1])
            f.write(str1)
        f.write("\r\n")
    else:
        print "The text can't be classified to the Four Labels!"
        return "Can't be classified ! "
    f.close()
    y, x = svmutil.svm_read_problem(str)
    model = svmutil.svm_load_model("../SVMTrainFile250.model")
    label, b, c = svmutil.svm_predict(y, x, model)
    print "label", label
    if label[0] == 1:
        print "类别:财经"
        return "财经"
    elif label[0] == 2:
        print "类别:IT"
        return "IT"
    elif label[0] == 3:
        print "类别:旅游"
        return "旅游"
    elif label[0] == 4:
        print "类别:体育"
        return "体育"
开发者ID:Joylim,项目名称:Classifier,代码行数:31,代码来源:textClassifier.py


示例8: kfold

def kfold(data, labels, k):
	try:
		import svmutil
	except:
		return 0
	prabs = []

	for xxx in range(0, 10):
		picks = np.random.choice(len(data), len(data) / k, replace=False)
		testLabel = labels[picks]
		testPoint = data[picks]
		trainPoint = data[np.setdiff1d(range(0, len(data)), picks)]
		trainLabel = labels[np.setdiff1d(range(0, len(data)), picks)]

		trainLabel = trainLabel.tolist()
		trainPoint = trainPoint.tolist()

		prob = svmutil.svm_problem(trainLabel, trainPoint)
		param = svmutil.svm_parameter('-t 3 -c 4 -b 1 -q')
		testLabel = testLabel.tolist()
		testPoint = testPoint.tolist()

		m = svmutil.svm_train(prob, param)
		svmutil.svm_save_model('n.model', m)

		p_label, p_acc, p_val = svmutil.svm_predict(testLabel, testPoint, m, '-b 1')

		prabs.append(p_acc[0])

	print sum(prabs) / float(len(prabs))
	print 'std' + str(np.std(prabs))
	return sum(prabs) / float(len(prabs))
开发者ID:mmorehea,项目名称:cellseer,代码行数:32,代码来源:fisher_cluster.py


示例9: getSamePeptideClusters

def getSamePeptideClusters(precMassClusters, scanFDict, svmModel, svmRange, ppmSTD=5, cutOff=0):
    trueClusters = []
    for cluster in precMassClusters:
        if len(cluster) == 1:
            trueClusters += [cluster]
        else:
#            print 'testing cluster', cluster
            pairIndex = []
            xVals = []
            specs = []
            for i in range(len(cluster)):
                specs +=  [DataFile.getMassIntPairs(scanFDict[cluster[i]]['dta'])]
                
            dMatrix = np.ones((len(cluster), len(cluster))) * -2
            for i in range(len(cluster)):
                for j in range(i+1, len(cluster)):
                    epSTD = ppmSTD * 10 ** -6 * scanFDict[cluster[i]]['precMass']
            
                    SVMClassificationInfo = SA.getSpectraPairInfoForSVMClassification(specs[i], specs[j], scanFDict[cluster[i]]['precMass'], NMod=0, CMod=0, epsilon=2*epSTD)
                    xVals += [SVMClassificationInfo]
                    pairIndex += [(i, j)]
            
            xValsNorm = svmutil.normalize_instances(xVals, svmRange)
            pLabs = svmutil.svm_predict([0]*len(xValsNorm), xValsNorm, svmModel)[0]
#            print pLabs
            for i, pLab in enumerate(pLabs):
            # Scale distances by 4: totalTICRatio, 1: TotalSharedPeaksRatio
                dMatrix[pairIndex[i][0]][pairIndex[i][1]] =  dMatrix[pairIndex[i][1]][pairIndex[i][0]] = xVals[i][1] if pLab==1 else -1

            trueClusters += heirarchicalClusteringAverageLinkage([[scanF] for scanF in cluster], dMatrix, cutOff=cutOff)
    
    return trueClusters
开发者ID:adevabhaktuni,项目名称:LADS,代码行数:32,代码来源:Analytics.py


示例10: TrainSvmLinear2

def TrainSvmLinear2(Y, X, sweep_c=range(-2,18)):
    num_positives = float(Y.count(1))
    num_negatives = float(Y.count(-1))

    best_c = -1
    best_acc = -1
    for c_pow in sweep_c:
        current_c = np.power(2.0,c_pow)
        param = svm.svm_parameter('-t 0 -c %f -w-1 %f -w1 %f -q' % (current_c,
                                                                    100/num_negatives,
                                                                    100/num_positives))
        current_pos_acc, current_neg_acc = CrossValidate(Y, X, param)
        current_acc = current_pos_acc
        print '%f, %f, %f' % (current_c, current_acc, current_neg_acc)
        if best_acc < current_acc:
            best_acc = current_acc
            best_c = current_c

    prob = svm.svm_problem(Y,X)
    param = svm.svm_parameter('-t 0 -c %f -w-1 %f -w1 %f -q' % (best_c,
                                                                100/num_negatives,
                                                                100/num_positives))
    svm_model = svm.svm_train(prob, param)
    p_labs, p_acc, p_vals = svm.svm_predict(Y, X, svm_model, '-q')
    return svm_model
开发者ID:CareShaw,项目名称:plex,代码行数:25,代码来源:svm_helpers.py


示例11: calc

 def calc(self,g1,*args):
     """ takes an unlimited number of grids as inputs and
         produces a new grid with the result of the model 
     """
     if(self.model==None):
         return None
     g=[g1]                   # list of used grids
     gout=grid.copy_grid(g1)  # build an output grid
     nrows,ncols=gout.size()  # store the size of the output
     for ar in args:
         g.append(ar)
     inp=np.zeros(len(g))
     inp=inp.tolist()
     for i in xrange(nrows):
         for j in xrange(ncols):
             if(gout.get(i,j)==gout.get_nodata()):
                 continue
             for k in range(len(g)):
                 if(g[k].get(i,j)==g[k].get_nodata()):
                     gout.set(i,j,gout.get_nodata())
                     break
                 inp[k]=g[k].get(i,j)
             inp1=[inp]
             l,acc,val=su.svm_predict([0]*len(inp1),inp1,self.model)
             gout.set(i,j,val[0][0])
     return gout
开发者ID:Ralf3,项目名称:samt2,代码行数:26,代码来源:svm_mod.py


示例12: train_test_model

def train_test_model(train_datafile, test_datafile):
    from svmutil import svm_read_problem, svm_train, svm_predict
    y,x = svm_read_problem(train_datafile)
    m = svm_train(y,x,'-t 0 -e .01 -m 1000 -h 0')
    y_test,x_test = svm_read_problem(test_datafile)
    p_labs,p_acc,p_vals = svm_predict(y_test,x_test,m)
    return p_labs, p_acc, p_vals
开发者ID:bauer90,项目名称:fluffy-hockeypuck,代码行数:7,代码来源:hw3_code_erhan.py


示例13: detectDoor

 def detectDoor(self, img, horOffset, verOffset):
     #print len(img.shape)
     if len(img.shape) > 2:
         img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
     Window = sw.SlidingWindow(64,128,img,horOffset,verOffset)
     horWin, verWin = Window.getWindows()
     windows = horWin*verWin
     print "windows %d " % windows
     print "windows %d " % horWin
     print "windows %d " % verWin 
     features = np.zeros((windows,3780),dtype = np.float)
     ones = np.ones((windows,1),dtype = np.float)
     labels = ones.ravel()
     for i in range(0,windows):
         print i
         imag = Window.getNextFrame()
         #cv2.imshow("Hello",imag)
         #cv2.waitKey(0)
         #cv2.destroyAllWindows()
         feature = self.hog.compute(imag)
         feature = np.transpose(feature);
         features[i] = feature
     labelsList = labels.tolist()
     featuresList = features.tolist()
     p_label, p_acc, p_val = svm.svm_predict(labelsList, featuresList, self.windowModel)
     return (p_label,p_acc,p_val)
开发者ID:osman-mian,项目名称:fyp,代码行数:26,代码来源:WindowDetector_backup.py


示例14: valid

	def valid(self,datasets,opt,opp,method = fold,part_ids = None,seed = None,test_data = None):
		if seed is None:
			# If seed is not set. UNIX time is used as seed.
			seed = time.time()
		saving_seed = "%s/log/%s.log.seed" % (self._dir,self._name)
		with open(saving_seed,"w") as fp:
			# Save used seed value.
			fp.write("seed:%f\n" % seed)
		
		if part_ids is None:
			part_ids = datasets.pids
		groups = [(test,train) for test,train in method(part_ids,seed = seed)]
		
		for cnt,pdtsts in enumerate(groups):
			# cnt is number of cluster.
			if test_data is None:
				test = False
				ltest,dtest,itest = test2svm_prob(datasets.mkTest(pdtsts[0]))
			else:
				test = True
				ltest,dtest,itest = test2svm_prob(test_data.mkTest(test_data.pids))

			print "start %s validation" % (cnt)
			ptrn,itrain = train2svm_prob(datasets.mkTrain(pdtsts[1]))
			#opt = svm.svm_parameter(opt)
			model = svmutil.svm_train(ptrn,opt)
			
			plbl,pacc,pval = svmutil.svm_predict(ltest,dtest,model,opp)

			# create saving direcotry
			#self._mkdir(cnt)
			# create log files
			self._save_log(itest,plbl,pval,cnt,test)
			model_name = "%s/model/%s.model.%s" % (self._dir,self._name,cnt)
开发者ID:masakibb2,项目名称:SBR_predictor,代码行数:34,代码来源:valid.py


示例15: TrainSvmRbf2

def TrainSvmRbf2(Y, X, sweep_c=range(-5,5), sweep_g=range(-5,5)):
    num_negatives = float(Y.count(-1))
    num_positives = float(Y.count(1))

    best_c = -1
    best_g = -1
    best_acc = -1
    for c_pow in sweep_c:
        for g_pow in sweep_g:
            current_c = np.power(2.0,c_pow)
            current_g = np.power(2.0,g_pow)
            prob = svm.svm_problem(Y,X)
            param = svm.svm_parameter('-t 2 -c %f -g %f -w-1 %f -w1 %f -q' % (current_c,
                                                                              current_g,
                                                                              100/num_negatives,
                                                                              100/num_positives))
            current_pos_acc, current_neg_acc = CrossValidate(Y, X, param)
            current_acc = current_pos_acc
            print 'c = %f, g = %f, cv acc = %f, neg acc = %f' % (current_c, current_g, current_acc,
                                                                 current_neg_acc)
            if best_acc < current_acc:
                best_acc = current_acc
                best_c = current_c
                best_g = current_g

    prob = svm.svm_problem(Y,X)
    param = svm.svm_parameter('-t 2 -c %f -g %f -w-1 %f -w1 %f -q' % (best_c, best_g,
                                                                      100/num_negatives,
                                                                      100/num_positives))
    svm_model = svm.svm_train(prob, param)
    p_labs, p_acc, p_vals = svm.svm_predict(Y, X, svm_model, '-q')
    pdb.set_trace()
    return svm_model
开发者ID:CareShaw,项目名称:plex,代码行数:33,代码来源:svm_helpers.py


示例16: UpdateWordsWithSvm

def UpdateWordsWithSvm(svm_model, word_results):
    svm_clf = svm_model[0]
    min_vals = svm_model[1][0]
    max_vals = svm_model[1][1]    

    if not word_results:
        return
    
    X_list = []
    n_features = -1
    for i in range(len(word_results)):
        word_result = word_results[i]
        char_bbs = word_result[1]
        word_score = word_result[0][0,4]
        features = ComputeWordFeatures(char_bbs, word_score)
        if n_features < 0:
            n_features = len(features)
        X_list.append(features)
        
    assert n_features > 0

    X_mat = np.vstack(X_list)
    X_mat = X_mat - min_vals
    X_mat = X_mat / max_vals
    X = [dict(zip(range(n_features), x_i)) for x_i in X_mat.tolist()]
    p_labs, p_acc, p_vals = svm.svm_predict([0]*len(X), X, svm_clf, '-q')
    labels = svm_clf.get_labels()

    for i in range(len(word_results)):
        word_result = word_results[i]
        if labels[0] < 0:
            word_result[0][0,4] = -p_vals[i][0]
        else:
            word_result[0][0,4] = p_vals[i][0]
开发者ID:CareShaw,项目名称:plex,代码行数:34,代码来源:svm_helpers.py


示例17: predict_all

def predict_all(request):
    '''Predicts points in an array'''
    
    width = float( request.POST.get("width", "None") )
    height = float( request.POST.get("height", "None") )
    
    model = svmutil.svm_load_model('libsvm.model')
    
    # Get grid of points to query
    points = []
    for counterY in [ 1.0 / 15.0 * y for y in range(0, 15) ]:
        for counterX in [ 1.0 / 15.0 * x for x in range(0, 15) ]:
            points.append([counterX, counterY])
    
    #for counterY in [ 1.0 / 10.0 * x for x in range(0, 10) ]:
    #    for counterX in [ 1.0 / 10.0 * y for y in range(0, 10) ]:
    #        label , acc, val = svmutil.svm_predict( [0], [[counterX, counterY]], model )
    #        results[i] = [counterX, counterY, label] 
    #        i = i + 1
    
    #results["length"] = i
    
    # Get labels
    labels, acc, val = svmutil.svm_predict([0] * len(points), points, model)
    
    results = {}
    for index, value in enumerate(points):
        results[index] = {  "x" : points[index][0], 
                            "y" : points[index][1], 
                            "label" : labels[index] }
    results["length"] = len(points)

    return json(results)
开发者ID:ericmok,项目名称:eri53,代码行数:33,代码来源:ajax.py


示例18: _test

 def _test(self, split, exclude):
     '''
     Tests all items in a split
     part of the data across
     everything else. Returns 
     all relevant statistics
     for F-score evaluation.
     '''
     falseNeg = 0
     falsePos = 0
     truePos = 0
     excludeLabels = []
     excludeData   = []
     for item in exclude:
         excludeLabels.append(item[1])
         excludeData.append(item[0])
     svm_m     = svm_model(excludeData,excludeLabels,
                           kernel=self.model.__svmparam__.kernel_type,
                           c=self.model.c)
     split_len = len(split[0])
     #for i in xrange(split_len):
     predict,acc,val = svmutil.svm_predict(split[1],split[0],svm_m.model)
     #print 'Predicted label: %d\t Real label:%d'%(int(predict[0]),int(split[1][i]))
     prediction, reality = predict, split[1]
     return (prediction, reality)
开发者ID:LabBlouin,项目名称:LabBlouinTools,代码行数:25,代码来源:svm.py


示例19: main

def main(path, k):
	
	prabs = []
	lns = []
	for kk in range(0,k-1):
		testLabel = []
		trainPoint = []
		trainLabel = []
		testPoint = []
		wcCount = 0
		for u in os.listdir(path): 
			if u[-2:] == 'WC':r
				wcCount += 1
				filePath = path+u
				WC = pickle.load(open(filePath, 'rb'))
				if wcCount % k == 0 + kk:
					testLabel.append(int(u[1]))
					testPoint.append(WC)
					
				else:
					trainLabel.append(int(u[1]))
					trainPoint.append(WC)

		lns.append(len(testLabel))
		prob = svmutil.svm_problem(trainLabel, trainPoint)
		param = svmutil.svm_parameter('-t 0 -c 4 -b 1 -q')


		m = svmutil.svm_train(prob, param)
		svmutil.svm_save_model('n.model', m)
		p_label, p_acc, p_val = svmutil.svm_predict(testLabel, testPoint, m, '-b 1')
		prabs.append(p_acc[0])
开发者ID:mmorehea,项目名称:cellseer,代码行数:32,代码来源:kfold.py


示例20: train_test

def train_test():
	train_subdir = "data/train/"
	test_subdir = "data/test/"
	img_kinds = ["happy", "anger", "neutral", "surprise"]
	models = {}
	params = "-t 0 -c 3"
	svm_params = {	"happy": params,
					"anger": params,
					"neutral": params,
					"surprise": params}

	#train the models
	print 'BUILDING TRAIN MODELS'
	for img_kind in img_kinds:
		print "\t" + img_kind
		problem = build_problem(img_kind, train_subdir)
		param = svm.svm_parameter(svm_params[img_kind])
		models[img_kind] = svmutil.svm_train(problem, param)
	print '================================'

	#for each image in test set let's see what is the answe
	total_count = 0
	correct_count = 0
	wrong_count = 0

	print 'TESTING MODELS'
	for img_kind in img_kinds:
		images = glob.glob(test_subdir + "f_" + img_kind + "*.jpg")
		for image in images:
			print "\t" + image
			image_data = cv.LoadImage(image)
			
			# Let's see what are the results from the models
			results = {}
			for kind in img_kinds:
				test_data = get_image_features(image_data, True, kind)
				predict_input_data = []
				predict_input_data.append(test_data)

				# do svm query
				(val, val_2, label) = svmutil.svm_predict([1] ,predict_input_data, models[kind])
				results[kind] = label[0][0]
			
			sorted_results = sorted(results.iteritems(), key=operator.itemgetter(1))
			result = sorted_results[len(sorted_results)-1][0]

			total_count += 1
			if result == img_kind:
				print 'YES :' + result
				correct_count += 1
			else:
				print 'NO  :' + result
				print sorted_results
				wrong_count += 1
			print '-----------------------'
	print '================================'
	print "Total Pictures: " + str(total_count)
	print "Correct: " + str(correct_count)
	print "Wrong: " + str(wrong_count)
	print "Accuracy: " + str(correct_count/float(total_count) * 100)
开发者ID:prabhat1992,项目名称:emotion_recognition,代码行数:60,代码来源:utils+-+Copy.py



注:本文中的svmutil.svm_predict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python svmutil.svm_train函数代码示例发布时间:2022-05-27
下一篇:
Python svmutil.svm_load_model函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap