Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. from sklearn.feature_selection import VarianceThreshold
  2. from sklearn.feature_selection import f_classif
  3. from sklearn.feature_selection import SelectKBest
  4.  
  5. #K best features
  6. KBESTNUM = 17000
  7.  
  8. print "ORIGINAL #FEATURES", trainingX.shape[1]
  9. print "removing features with zero variance"
  10. sel = VarianceThreshold()#threshold = (.000005))
  11. trainingX = sel.fit_transform(trainingX)
  12. validationSet = sel.transform(validationSet)
  13. print "AFTER VARIANCE REMOVAL", trainingX.shape[1]
  14. print "feature selecting using " +str(KBESTNUM)
  15.  
  16. kBest = SelectKBest(f_classif,k=KBESTNUM)
  17. trainingX = kBest.fit_transform(trainingX,trainingY)
  18. validationSet = kBest.transform(validationSet)
  19.  
  20.  
  21. print "done selecting features"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement