Complete the code to import the SelectKBest feature selector from scikit-learn.
from sklearn.feature_selection import [1]
The SelectKBest class is used for feature selection by selecting the top k features based on a scoring function.
Complete the code to select the top 5 features using SelectKBest with the chi2 scoring function.
selector = SelectKBest(score_func=[1], k=5)
The chi2 function is a common scoring function used with SelectKBest for classification tasks with non-negative features.
Fix the error in the code to correctly fit the feature selector to the data X and labels y.
selector = SelectKBest(score_func=chi2, k=3) selector.[1](X, y)
The fit method trains the selector to find the best features based on X and y.
Fill both blanks to create a dictionary of feature scores and select features with scores greater than 10.
scores = {feature: score for feature, score in zip(feature_names, selector.scores_)}
selected_features = [feature for feature, score in scores.items() if score [1] [2]]This code selects features whose scores are greater than 10.
Fill all three blanks to create a new dataset X_new with selected features and print its shape.
X_new = selector.[1](X) print('Selected features shape:', X_new.[2]) num_features = X_new.[3]
The transform method applies feature selection to X. shape gives the dimensions of the array, and shape[1] gives the number of columns (features).