Feature Selection Python

[Solved] Feature Selection Python | Shell - Code Explorer | yomemimo.com
Question : how to feature selection in python

Answered by : hasya-patel

>>> from sklearn.datasets import load_iris
>>> from sklearn.feature_selection import SelectKBest
>>> from sklearn.feature_selection import chi2
>>> X, y = load_iris(return_X_y=True)
>>> X.shape
(150, 4)
>>> X_new = SelectKBest(chi2, k=2).fit_transform(X, y)
>>> X_new.shape
(150, 2)

Source : | Last Update : Sun, 30 Jan 22

Question : feature selection python

Answered by : jjsseexx

from sklearn.feature_selection import VarianceThreshold
sel = VarianceThreshold(threshold=(0.95 * (1 - 0.95)))
sel_=sel.fit_transform(features)

Source : | Last Update : Mon, 22 Nov 21

Question : feature selection python

Answered by : nasir-usman

You can change the direction using the direction parameter
direction{'forward', 'backward'}, default='forward'
>>> from sklearn.feature_selection import SequentialFeatureSelector
>>> from sklearn.neighbors import KNeighborsClassifier
>>> from sklearn.datasets import load_iris
>>> X, y = load_iris(return_X_y=True)
>>> knn = KNeighborsClassifier(n_neighbors=3)
>>> sfs = SequentialFeatureSelector(knn, n_features_to_select=3)
>>> sfs.fit(X, y)
SequentialFeatureSelector(estimator=KNeighborsClassifier(n_neighbors=3), n_features_to_select=3)
>>> sfs.get_support()
array([ True, False, True, True])
>>> sfs.transform(X).shape
(150, 3)

Source : https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SequentialFeatureSelector.html | Last Update : Sun, 11 Sep 22

Answers related to feature selection python

Code Explorer Popular Question For Shell