0

I am wondering if it is possbile to define feature importances/weights in Pyhton Classification methods? For example:

model = tree.DecisionTreeClassifier(feature_weight = ...) 

I've seen in RandomForest there is an attribute feature_importance, which shows the importance of features based on analysis. But is it possible that I could define the feature importance for analysis in advance?

Thank you very much for your help in advance!

4
  • Because there's overfitting in my analysis, I can say for sure that some features are more important than the others. That is why I am wondering if I can define the importances in advance. Commented Jan 15, 2019 at 12:15
  • Possible duplicate of How to put more weight on certain features in machine learning? Commented Jan 15, 2019 at 12:29
  • In your case, I would go with Feature Selection, and keep the distinctive features only for training scikit-learn.org/stable/modules/feature_selection.html Commented Jan 15, 2019 at 12:32
  • Okay! Thanks a lot! I'll go with feature selection and remove the ones that are less important. Commented Jan 15, 2019 at 12:41

1 Answer 1

1

The feature importance determination in random forest classifiers uses a random forest-specific method (invert all binary tests over the feature, and get the additional classification error).

Feature importance is thus a concept that relates to the predictive ability of the model, not the training phase. Now, if you want to make it so that your model favours some feature over others, you will have to find some trick that depends on the model.

Regarding sklearn's DecisionTreeClassifier, such a trick does not appear to be trivial. You could custom your class weights, if you know some classes will be more easily predicted by some features that you want to favour; but this seems pretty dirty.

In other types of models, such as ones using kernels, you can do this more easily, by setting hyperparameters which directly relate to features.

If you are trying to limit an overfitting, I would also simply suggest that you remove the features you know to be less important.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! This helps to solve my problem. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.