Machine learning online compiler (scikit-learn)
Train and test scikit-learn models in your browser, free. The code runs in a sandbox on our servers with scikit-learn, pandas, NumPy and Matplotlib installed. No sign-in, no ads, nothing to set up.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, confusion_matrix
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
model = DecisionTreeClassifier(random_state=42)
model.fit(X_train, y_train)
pred = model.predict(X_test)
print("Accuracy:", round(accuracy_score(y_test, pred), 3))
print(confusion_matrix(y_test, pred))Press Run and the decision tree is trained and tested on the iris dataset:
Accuracy: 1.0
[[19 0 0]
[ 0 13 0]
[ 0 0 13]]What you can run
Classical machine learning on small data: regression, classification, clustering, decision trees, random forests, SVMs, k-nearest neighbours, PCA, cross-validation and pipelines with scikit-learn 1.9.1, and statistical models with statsmodels 0.15.0. Each run gets 30 seconds, 512 MB of memory (up to 2 GB on Pro and Business) and 2 CPUs, which is plenty for course-sized datasets.
Neural networks written from scratch in NumPy run too. This two-layer network learns handwritten digits in
about two seconds and prints Test accuracy: 0.958:
import numpy as np
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
X, y = load_digits(return_X_y=True)
X = X / 16.0
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
rng = np.random.default_rng(0)
W1 = rng.normal(0, 0.1, (64, 32)); b1 = np.zeros(32)
W2 = rng.normal(0, 0.1, (32, 10)); b2 = np.zeros(10)
Y = np.eye(10)[y_train]
for epoch in range(300):
h = np.maximum(0, X_train @ W1 + b1) # ReLU layer
logits = h @ W2 + b2
p = np.exp(logits - logits.max(1, keepdims=True))
p /= p.sum(1, keepdims=True) # softmax
d2 = (p - Y) / len(X_train) # backpropagation
d1 = (d2 @ W2.T) * (h > 0)
W2 -= 0.5 * h.T @ d2; b2 -= 0.5 * d2.sum(0)
W1 -= 0.5 * X_train.T @ d1; b1 -= 0.5 * d1.sum(0)
pred = (np.maximum(0, X_test @ W1 + b1) @ W2 + b2).argmax(1)
print("Test accuracy:", round((pred == y_test).mean(), 3))Datasets
scikit-learn's bundled datasets are installed and load instantly: load_iris, load_digits, load_wine, load_breast_cancer and load_diabetes.
seaborn's 22 sample datasets load through sns.load_dataset, such as "titanic", "penguins" and "diamonds".
The fetch_ functions, such as fetch_california_housing and fetch_openml, download their data from the internet, and programs here have no network, so they stop
with URLError: Temporary failure in name resolution. For your own data, paste a CSV into the Input
tab and read it with pd.read_csv(sys.stdin); the pandas online
compiler page shows how.
For text and NLP labs, NLTK is installed with WordNet (for WordNetLemmatizer), the VADER sentiment
lexicon and the English part-of-speech tagger, and wordcloud draws word clouds. A call to nltk.download prints an error, since there is no network, but that data is already there. NLTK's
stopwords and the punkt data that word_tokenize needs are not included. Loading WordNet takes several
seconds of the run.
What doesn't fit
- PyTorch, TensorFlow and Keras are not installed, and there is no GPU.
- Training that takes longer than 30 seconds is stopped, so keep models and data small.
- Nothing is kept between runs: the program trains and predicts in the same run.
For deep learning, GPUs or long training, use a notebook service such as Google Colab or Kaggle. How this compares with Colab.
Check a model's result automatically
To grade a model, print a rounded score and compare it with the "Numbers within" option of the Python compiler with test cases, or print PASS when the score clears a threshold:
score = accuracy_score(y_test, pred)
print("PASS" if score >= 0.9 else "FAIL")Fix every random seed so the score is the same on every run. Course and practice sites can grade the same way through the autograder API.
Run models from your own app
Send the code and a data file to the API, and the output comes back in the response. This example fits a linear regression and predicts the price of a four-room house. It's free up to 100,000 runs a month.
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "python-3.14",
"code": "import pandas as pd\nfrom sklearn.linear_model import LinearRegression\n\ndf = pd.read_csv(\"houses.csv\")\nmodel = LinearRegression().fit(df[[\"rooms\"]], df[\"price\"])\nprint(round(model.predict(pd.DataFrame({\"rooms\": [4]}))[0], 1))",
"files": [
{"name": "houses.csv", "content": "rooms,price\n1,50\n2,80\n3,110\n5,170\n"}
]
}'The response's output is "140.0\n". The data science code execution API page covers the runtimes,
files and grading in more detail.
Frequently asked questions
Is scikit-learn installed?
Yes. scikit-learn 1.9.1 runs on Python 3.14 with NumPy, SciPy, pandas, statsmodels 0.15.0, Matplotlib and seaborn. Nothing needs installing, and the page needs no sign-in.
Can I use PyTorch or TensorFlow?
No. PyTorch, TensorFlow and Keras are not installed, there is no GPU, and programs have no network to install packages. For deep learning, use Google Colab or Kaggle notebooks. A small neural network written in NumPy does run here.
Why does fetch_california_housing fail?
scikit-learn's fetch_ functions download their data the first time, and programs here have no network, so they stop with URLError: Temporary failure in name resolution. The load_ datasets, such as load_iris and load_digits, are installed and work. You can also paste your own CSV into the Input tab.
Can I train on my own data?
Yes. Paste a CSV into the Input tab, up to 100 KB, and read it with pd.read_csv(sys.stdin). Through the API you can send up to 20 files, 1 MB in total.
Are the results repeatable?
Yes, if you fix the random seeds: pass random_state to train_test_split and to the model, and seed NumPy's generator. Every run gets the same 2 CPUs, so the same code and seeds give the same scores.