Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:25:34+00:00 2026-06-12T18:25:34+00:00

I am using sci-kit learn (version 0.11 with Python version 2.7.3) to select the

  • 0

I am using sci-kit learn (version 0.11 with Python version 2.7.3) to select the top K features from a binary classification dataset in svmlight format.

I am trying to identify the feature-id values of the selected features. I assumed this would be quite simple – and may well be!
(By feature-id, I mean the number before the feature value as described here)

The following code illustrates exactly how I have been trying to do this:

from sklearn.datasets import load_svmlight_file
from sklearn.feature_selection import SelectKBest

svmlight_format_train_file = 'contrived_svmlight_train_file.txt' #I present the contents of this file below

X_train_data, Y_train_data = load_svmlight_file(svmlight_format_train_file)

featureSelector = SelectKBest(score_func=chi2,k=2)

featureSelector.fit(X_train_data,Y_train_data)

assumed_to_be_the_feature_ids_of_the_top_k_features = list(featureSelector.get_support(indices=True)) #indices=False just gives me a list of True,False etc...

print assumed_to_be_the_feature_ids_of_the_top_k_features #this gives: [0, 2]

Clearly, assumed_to_be_the_feature_ids_of_the_top_k_features cannot correspond to the feature-id values – since (see below) the feature-id values in my input file start from 1.

Now, I suspect that assumed_to_be_the_feature_ids_of_the_top_k_features may, in fact, correspond to the list indices of the feature-id values sorted in order of increasing value. In my case, index 0 would correspond to feature-id=1 etc. – such that the code is telling me that feature-id=1 and feature-id=3 were selected.

I’d be grateful if someone could either confirm or deny this, however.

Thanks in advance.

Contents of contrived_svmlight_train_file.txt:

1 1:1.000000 2:1.000000 4:1.000000 6:1.000000#mA
1 1:1.000000 2:1.000000#mB
0 5:1.000000#mC
1 1:1.000000 2:1.000000#mD
0 3:1.000000 4:1.000000#mE
0 3:1.000000#mF
0 2:1.000000 4:1.000000 5:1.000000 6:1.000000#mG
0 2:1.000000#mH

P.S. Apologies for not formatting correctly (first time here); I hope this is legible and comprehensible!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:25:35+00:00Added an answer on June 12, 2026 at 6:25 pm

    Clearly, assumed_to_be_the_feature_ids_of_the_top_k_features cannot correspond to the feature-id values – since (see below) the feature-id values in my input file start from 1.

    Actually, they are. The SVMlight format loader will detect that your input file has one-based indices and will subtract one from every index so as not to waste a column. If that’s not what you want, then pass zero_based=True to load_svmlight_file to pretend that it’s actually zero-based and insert an extra column; see its documentation for details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to select the best features using chi-square (scikit-learn 0.10). From a
I have a classifier that I trained using Python's scikit-learn. How can I use
I am using scikit-learn for some data analysis, and my dataset has some missing
I'm using scikit-learn to cluster text documents. I'm using the classes CountVectorizer, TfidfTransformer and
Is there a way to perform sequential k-means clustering using scikit-learn? I can't seem
Using SQL Server 2008 R2 we are looking for a way to select the
Using import datetime in python, is it possible to take a formatted time/date string
Scikit-learn has fairly user-friendly python modules for machine learning. I am trying to train
I am trying to build a python module (scikit.timeseries) using python setup.py build but
I was using the Mersenne-Twister implementation at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVA/MTRandom.java as a drop-in replacement for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.