# scikit-learn and PyTorch

> The free Python tools most models are built with. scikit-learn for classic models on tables. PyTorch and TensorFlow for networks.

**Course:** [Machine Learning](https://learn.benibix.com/learn/ai-machine-learning)  
**Time:** 12 min

**After this lesson you can:**

- Pick a library for a task
- Read a short scikit-learn script
- Say where PyTorch and TensorFlow differ

## Which library to build a model with

Most machine learning is built with a few free Python libraries. scikit-learn holds the classic models: linear and logistic regression, trees, forests, k-means and more. PyTorch and TensorFlow are for neural networks. scikit-learn began in 2007 and first came out in 2010. TensorFlow came out in 2015, and PyTorch in 2017.

scikit-learn is built for tables of data that fit on one computer. Every model works the same way: you call fit to train it and predict to use it. Swapping a forest for a k-NN model is a one-line change. It also has the tools to split, scale and score data.

It does not train deep neural networks, and it does not use graphics chips. For a spreadsheet of sales or sign-ups, that rarely matters. A forest on 100,000 rows can train in seconds on a laptop. Boosting libraries like XGBoost follow the same fit and predict pattern.

PyTorch is for building and training neural networks. You write the network as normal Python code, layer by layer, and it works out the gradients for you. The same code runs on a laptop chip or a graphics card. Most AI research today uses it, and since 2022 it has been run by an independent foundation.

TensorFlow does the same job. Most people use it through a simple layer-stacking tool that comes with it. Its strength is shipping: tools to run a finished model on phones, in web pages and on servers. Many firms still run models built with it, though new research has mostly moved to PyTorch.

A rule of thumb covers most cases. For rows and columns, start with scikit-learn, and move to a boosting library if you need more. For photos, sound or text, use PyTorch. For a model that must run inside a phone app, check what each library offers for phones before you pick.

People often reach for PyTorch for a table of 5,000 rows. A neural network there needs more code, more tuning, and usually scores no better than a forest. The plainest model that does the job is easier to check and to keep running.

```python
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier

# X holds the features, y holds the labels
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = RandomForestClassifier(n_estimators=300)
model.fit(X_train, y_train)
print(model.score(X_test, y_test))
```
Hold back 20% of the rows, train a forest of 300 trees with fit, and score it on the rows it never saw.

## The three libraries side by side

| Library | Built for | Typical use |
| --- | --- | --- |
| scikit-learn | Classic models on tables | Forests, regression, clustering |
| PyTorch | Neural networks, research first | Photo, sound and text models |
| TensorFlow | Neural networks, shipping first | Models inside phones and web pages |

## Which one to pick

1. **Pick scikit-learn.** When your data is a table that fits on one computer.
2. **Pick PyTorch.** When you build a neural network for photos, sound or text.
3. **Pick TensorFlow.** When the finished model must run inside a phone or a web page.

![Your Python code sits on top of two kinds of library. For classic models on table data, scikit-learn and XGBoost run on the CPU. For neural networks, PyTorch and TensorFlow run on the CPU or a graphics card.](https://learn.benibix.com/diagrams/ai3-ml-frameworks.svg)

### Example: Emma builds her first model

Emma has a table of 8,000 past loans with 15 columns each. She trains a scikit-learn random forest in 7 lines, and it takes 4 seconds.

She tries a PyTorch network on the same table. It takes a day to set up and scores 1 point lower, so the forest stays.

**Words in this lesson:** [scikit-learn](https://learn.benibix.com/term/ai/scikit-learn), [PyTorch](https://learn.benibix.com/term/ai/pytorch), [TensorFlow](https://learn.benibix.com/term/ai/tensorflow)

> **The one thing to remember.** Use scikit-learn for tables and PyTorch for neural networks. Pick the tool by the shape of your data, not by what is in fashion.

**Question:** Which tool suits a forest model on a sales table?

**Answer:** scikit-learn, built for classic models on tables. scikit-learn holds the classic models and is built for tables that fit on one computer. A forest there needs a few lines and trains in seconds.

---

Source: https://learn.benibix.com/learn/ai-machine-learning/scikit-learn-and-pytorch
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
