기계 학습-sklearn 의 흔 한 사용

1167 단어 기계 학습
#      
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()          #    
clf.fit(features_train,labels_train)     
pred = clf.predit(features_test)        #      ,    

from sklearn.metrics import accuracy_score
accuracy = accuracy_score(pred, labels_test)   #      

#-------------------------------------------------------------------------------------------
# SVM     ,                   (     )
from sklearn.svm import SVC

clf = SVC(C=10000,kernel='rbf')     # C         ,kernel    , linear\rbf\polynomial 
t0 = time()                          # C    ,        
clf.fit(features_train,labels_train)
print "train time is :" , round(time()-t0, 3), "s"    

t0 = time()
pred = clf.predict(features_test)
print "fit time is :" , round(time()-t0,3), "s"
#print pred[10],pred[26],pred[50]               #    10/26/50     

from sklearn.metrics import accuracy_score
acc = accuracy_score(pred, labels_test)
print acc                                      #    

#--------------------------------------------------------------------------------------------


좋은 웹페이지 즐겨찾기