Python Forum
Feature Selection in Machine Learning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feature Selection in Machine Learning
#3
For feature selection in machine learning, you can use techniques like Recursive Feature Elimination (RFE) or feature importance from tree-based models. In your case, since you're using a RandomForestClassifier, you can leverage the feature_importances_ attribute to rank features based on their importance. For example:

python
Copy code
# Train a RandomForestClassifier
model = RandomForestClassifier()
model.fit(X, y)

# Get feature importances
feature_importances = model.feature_importances_

# Create a DataFrame to display feature names and their importances
feature_importance_df = pd.DataFrame({'Feature': X.columns, 'Importance': feature_importances})

# Sort features by importance in descending order
feature_importance_df = feature_importance_df.sort_values(by='Importance', ascending=False)

# Print or visualize the sorted feature importances
print(feature_importance_df)
You can then decide on a threshold for importance and keep only the top features. Additionally, you might want to explore other methods like Univariate Feature Selection or model-based selection using tools like SelectKBest or SelectFromModel in scikit-learn. Remember to assess the impact of feature selection on your model's performance using techniques like cross-validation. Check out scikit-learn's documentation and tutorials on feature selection for more details.

I recommend reading articles on machine learning and AI, such as those on platforms like Towards Data Science, to deepen your understanding of feature selection and its implications.
buran write Nov-15-2023, 12:37 PM:
Clickbait link removed
buran write Nov-15-2023, 12:37 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Feature Selection in Machine Learning - by shiv11 - Jul-24-2023, 10:25 AM
RE: Feature Selection in Machine Learning - by Samanthaaa - Nov-15-2023, 12:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Forest to Identify Page: Feature Selection JaneTan 0 1,393 Oct-14-2021, 09:40 AM
Last Post: JaneTan
  [machine learning] identifying a number 0-9 from a 28x28 picture, not working SheeppOSU 0 1,944 Apr-09-2021, 12:38 AM
Last Post: SheeppOSU
  Getting started in Machine Learning Harshil 5 3,422 Dec-07-2020, 04:06 PM
Last Post: sridhar
  Python Machine Learning: For Data Extraction JaneTan 0 1,944 Nov-24-2020, 06:45 AM
Last Post: JaneTan
  IndexError in Array while trying to do machine learning Mariaoye 0 2,001 Nov-12-2020, 12:35 AM
Last Post: Mariaoye
  Feature Selection with different units and strings ltloug01 2 2,112 Oct-16-2020, 01:24 AM
Last Post: jefsummers
  Errors with Machine Learning trading bot-- not sure why MattKahn13 0 1,448 Aug-07-2020, 08:19 PM
Last Post: MattKahn13
  How useful is PCA for machine learning? Marvin93 0 1,610 Aug-07-2020, 02:07 PM
Last Post: Marvin93
  How to extract data from paragraph using Machine Learning with python? bccsthilina 2 3,230 Jul-27-2020, 07:02 AM
Last Post: hussainmujtaba
  Machine Learning: Process Enanda 13 4,640 Mar-18-2020, 02:02 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020