Exemple #1
0
#		model=SVC(C=c,gamma=g)
#		print('Fitting model with params c: %f, g: %f ...'%(c,g))
#		model=model.fit(trset,trlabels)
#		try:
#			scorei=model.score(cvset,cvlabels)
#		except:
#			scorei=0 # something went wrong...
#		scores[counter]=np.mean(scorei)
#		paramholder[counter,0]=c
#		paramholder[counter,1]=g
#		if scorei>bestscore:
#			bestscore=scorei
#			bestmodel=model
#		counter+=1
#		print('Score = %f with c: %f, g: %f' %(scorei,c,g))
#bestc=paramholder[scores.argmax(),0]
#bestg=paramholder[scores.argmax(),1]
#print('Best score of %f with c: %f, g: %f' %(bestscore,bestc,bestg))
print('Fitting model with params c: %f, g: %f ...'%(c,g))
model=SVC(C=c,gamma=g)
model=model.fit(trset,trlabels)

pickle.dump(model,open('data/svm_c5_g05.p','wb'))

# predict test set
testx=imt.loadimgfromcsv(testfile,colstart=0)/255.0
ntest=testx.shape[0]
preds = model.predict(testx)
# output to .csv file labels
imt.writeoutpred(map(int,preds),np.arange(ntest)+1,outfile,header=["ImageId","Label"])
Exemple #2
0
        nx = x.shape[0]
        for zz in range(nx):
            sdAE.GD(x[zz].reshape(x.shape[1], 1), labels[lcount], alpha=0.1)
            lcount += 1
            iter += 1
        # check model with CV set
        cvscore = sdAE.score(cvset, cvlabels)
        if cvscore >= bestscore:
            # best so far, but wait a bit
            if cvscore >= bestscore * improvethresh:
                # increase patience
                patience = np.maximum(patience, iter * patienceinc)
            bestscore = cvscore
        if iter >= patience:
            # done!
            loopflag = True
            print('Exiting optimization. CV score= %3f' % cvscore)
            break  # out of block loop
    ep += 1

# pickle the best model
pickle.dump(sdAE, open('data/finetuned.p', 'wb'))

# predict labels from test dataset
# process in all at once
testx = imt.loadimgfromcsv(testfile, colstart=0) / 255.0
ntest = testx.shape[0]
preds = sdAE.predict(testx.T)
# output to .csv file labels
imt.writeoutpred(preds, range(ntest) + 1, outfile, header=["ImageId", "Label"])
Exemple #3
0
#		model=model.fit(trset,trlabels)
#		try:
#			scorei=model.score(cvset,cvlabels)
#		except:
#			scorei=0 # something went wrong...
#		scores[counter]=np.mean(scorei)
#		paramholder[counter,0]=c
#		paramholder[counter,1]=g
#		if scorei>bestscore:
#			bestscore=scorei
#			bestmodel=model
#		counter+=1
#		print('Score = %f with c: %f, g: %f' %(scorei,c,g))
#bestc=paramholder[scores.argmax(),0]
#bestg=paramholder[scores.argmax(),1]
#print('Best score of %f with c: %f, g: %f' %(bestscore,bestc,bestg))
print('Fitting model with params c: %f, g: %f ...' % (c, g))
model = SVC(C=c, gamma=g)
model = model.fit(trset, trlabels)

pickle.dump(model, open('data/svm_c5_g05.p', 'wb'))

# predict test set
testx = imt.loadimgfromcsv(testfile, colstart=0) / 255.0
ntest = testx.shape[0]
preds = model.predict(testx)
# output to .csv file labels
imt.writeoutpred(map(int, preds),
                 np.arange(ntest) + 1,
                 outfile,
                 header=["ImageId", "Label"])
Exemple #4
0
        nx=x.shape[0]
        for zz in range(nx):
            sdAE.GD(x[zz].reshape(x.shape[1],1),labels[lcount],alpha=0.1)
            lcount+=1
            iter+=1
        # check model with CV set
        cvscore=sdAE.score(cvset,cvlabels)
        if cvscore >= bestscore:
            # best so far, but wait a bit
            if cvscore >= bestscore*improvethresh:
                # increase patience
                patience = np.maximum(patience,iter*patienceinc)
            bestscore = cvscore
        if iter >= patience:
            # done!
            loopflag=True
            print('Exiting optimization. CV score= %3f'%cvscore)
            break # out of block loop
    ep+=1   

# pickle the best model
pickle.dump(sdAE,open('data/finetuned.p','wb'))

# predict labels from test dataset
# process in all at once
testx=imt.loadimgfromcsv(testfile,colstart=0)/255.0
ntest=testx.shape[0]
preds = sdAE.predict(testx.T)
# output to .csv file labels
imt.writeoutpred(preds,range(ntest)+1,outfile,header=["ImageId","Label"])