scikit-learn
MLMachine learning
What is scikit-learn?
Scikit-learn is Python's most popular machine learning library. It provides simple and consistent APIs for classification, regression, clustering, dimensionality reduction, model selection, and preprocessing. Scikit-learn is the starting point for virtually every machine learning project in Python.
PyRun supports scikit-learn as part of the Pyodide distribution, meaning you can train classifiers, compute accuracy scores, and explore ML algorithms entirely in your browser. It's a powerful educational tool — run the Iris classifier, experiment with hyperparameters, and see results without a cloud notebook.
Code Example
Train a Random Forest on the Iris dataset.
Scikit-learn Classifier
Try in Editorfrom sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42
)
clf = RandomForestClassifier(n_estimators=50, random_state=42)
clf.fit(X_train, y_train)
preds = clf.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, preds):.2%}\n")
print("Classification Report:")
print(classification_report(y_test, preds, target_names=iris.target_names))Why run scikit-learn in PyRun?
- ✦ Zero setup — no pip install, no virtual environment, no Python download
- ✦ Instant results — powered by WebAssembly, runs locally in your browser
- ✦ Share your code — generate a link and anyone can run it instantly
- ✦ Works offline — after first load, PyRun runs without internet