Prompt:
"Write Python code to train a Random Forest model and visualize feature importance."
Output:
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier() X, y = df.drop(columns=['target']), df['target'] model.fit(X, y)
importances = pd.Series(model.feature_importances_, index=X.columns).sort_values(ascending=False) importances.plot(kind='bar') plt.title('Feature Importance') plt.show()
Output Explanation: A bar chart of feature importances ranked by their impact on model performance.