svm - How to get the selected features after LinearSVC reduction in scikit -


the title all, have checked scikit docs, poor particular task, , have checked several online resources, including this post.

however, seem wrong. feature selection can like:

clf=linearsvc(penalty="l1",dual=false,random_state=0) x_reduced = clf.fit_transform(x_full,y_full) 

now, if inspect shape of x_reduced, clear how many features selected. question now, ones?

the coef_ attribute of linearsvc important , suggested iterate on , features coef_ different 0 ones selected. well, this wrong, can close real result.

after checking x_reduced, noticed got 310 selected features, , sure, mean, checking resultant matrix, now, if coef_ thing, 414 features selected, total of 2000, close real thing.

according scikit linearsvc docs there mean(x) involved threshold=none stuck, no idea now.

update: here link data&code reproduce error, few kb

i think linearsvc() returns features non-zero coefficients. please upload sample data file , code script (for example, via dropbox sharelink) can reproduce inconsistency saw?

from sklearn.datasets import make_classification sklearn.datasets import load_svmlight_file sklearn.svm import linearsvc import numpy np  x, y = load_svmlight_file("/home/jian/downloads/errorscikit/weirddata")  transformer = linearsvc(penalty='l1', dual=false, random_state=0) transformer.fit(x, y) # set threshold eps x_reduced = transformer.transform(x, threshold=np.finfo(np.float).eps)  print(str(x_reduced.shape[1]) + " equal " + str((transformer.coef_ != 0).sum()))  414 equal 414   # suggested user3914041, if want both sides 310 transformer.transform(x).shape  out[46]: (62, 310)  (abs(transformer.coef_) > 1e-5).sum()  out[47]: 310 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -