Created
July 6, 2020 05:57
-
-
Save finlytics-hub/0e978f2846bc32a570360ea3998f8d2c to your computer and use it in GitHub Desktop.
Practical demonstration of VarianceThreshold() without string columns
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
# import the required library | |
from sklearn.feature_selection import VarianceThreshold | |
# define the transform | |
# default threshold parameter is 0, can be set to any float value. All features with variance below this threshold will be removed | |
selector = VarianceThreshold(threshold = 0) | |
# fit the defined transform on training dataset | |
selector.fit(X_train) | |
# transform the training dataset and save as a new DF (don't forget to transform the test dataset as well) | |
X_train_clean = pd.DataFrame(selector.transform(X_train), columns = X_train.columns[selector.get_support(indices=False)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment