Last active
July 15, 2020 11:59
-
-
Save Ayushijain09/28932e641c8516286907fbd02f005c79 to your computer and use it in GitHub Desktop.
Mutual Information for Regression
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.feature_selection import mutual_info_regression | |
from sklearn.feature_selection import SelectKBest | |
selector = SelectKBest(mutual_info_regression, k=10) | |
X_train_new = selector.fit_transform(X_train, y_train) #Applying transformation to the training set | |
#to get names of the selected features | |
mask = selector.get_support() # Output array([False, False, True, True, True, False ....]) | |
print(selector.scores_) #Output array([0.16978127, 0.01829886, 0.45461366, 0.55126343, 0.66081217, 0.27715287 ....]) | |
new_features = X_train.columns[mask] | |
print(new_features) #Output Index(['wheelbase', 'carlength', 'carwidth', 'curbweight', 'enginesize','boreratio', 'horsepower', 'citympg', 'highwaympg', 'fuelsystem_2bbl'],dtype='object') | |
print(train.shape) #Output (143, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment