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.
from 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
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.