write me python scikit-learn random code
- User
write me python scikit-learn random code
Assistant
Here is a simple example of using scikit-learn to train a random forest classifier on a sample dataset and make predictions:
import numpy as np import pandas as pd from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from sklearn.datasets import make_classification # Generate a random dataset X, y = make_classification(n_samples=1000, n_features=10, random_state=42) # Split the dataset into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) # Train a random forest classifier clf = RandomForestClassifier(n_estimators=100, random_state=42) clf.fit(X_train, y_train) # Make predictions on the test set y_pred = clf.predict(X_test) # Print the accuracy of the model print('Accuracy:', np.mean(y_pred == y_test))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.