Created
July 16, 2020 20:19
-
-
Save Ayushijain09/885200ac34f0b9c8521ccfad043c2471 to your computer and use it in GitHub Desktop.
Tree Model for Feature Selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.tree import DecisionTreeRegressor | |
model = DecisionTreeRegressor() | |
# fit the model | |
model.fit(X_train, y_train) | |
# get importance | |
importance = model.feature_importances_ | |
# summarize feature importance | |
impList = zip(X_train.columns, importance) | |
for feature in sorted(impList, key = lambda t: t[1], reverse=True): | |
print(feature) | |
#Output - Important features | |
""" ('enginesize', 0.6348884035234398) | |
('curbweight', 0.2389770360203148) | |
('horsepower', 0.03458620700119025) | |
('carwidth', 0.027170640676336785) | |
('stroke', 0.012516866412495744) | |
('peakrpm', 0.011750282673996262) | |
('carCompany_bmw', 0.009801675326218959) | |
('carlength', 0.008737911775028553) ..... """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment