Prompt:
"Write Python code to compute mutual information scores for all features relative to a target variable."
Output:
from sklearn.feature_selection import mutual_info_classif
from sklearn.datasets import load_iris iris = load_iris() df = pd.DataFrame(iris.data, columns=iris.feature_names) df['target'] = iris.target
mi_scores = mutual_info_classif(df.drop(columns=['target']), df['target']) mi_scores = pd.Series(mi_scores, index=df.columns[:-1]).sort_values(ascending=False)
mi_scores
Output Explanation: A ranked list of features with their mutual information scores, indicating the predictive power of each feature.