What Is scikit-learn? The First Machine Learning Library to Learn
scikit-learn is the standard Python library for classic machine learning. See what it does, how to install it, and a complete first model in a few lines.
Short answer: scikit-learn is a free, open-source Python library for classic machine learning. It gives you ready-made tools for training models, splitting data, preparing features and measuring results, all through one consistent interface. It is the usual first library to learn for machine learning on tables of data, before moving on to deep learning tools.
What can you do with scikit-learn?
Task | What it means | Example tools in scikit-learn |
|---|---|---|
Classification | Predict a category | Logistic regression, decision trees, random forests |
Regression | Predict a number | Linear regression, gradient boosting |
Clustering | Find groups without labels | K-means |
Preprocessing | Prepare data | Scaling, one-hot encoding, filling missing values |
Model selection | Test and compare | Train/test split, cross-validation, metrics |
It focuses on traditional machine learning, which is described in types of machine learning. It is not meant for training large neural networks; libraries such as PyTorch and TensorFlow are used for that. See AI vs machine learning vs deep learning for the difference.
How do you install scikit-learn?
Run this in a terminal, ideally inside a virtual environment:
pip install scikit-learnThe package is named scikit-learn, but you import it as sklearn. It builds on NumPy, so see NumPy arrays for AI if arrays are new to you.
What does a first scikit-learn model look like?
This example trains a classifier on the famous iris dataset that ships with the library. It follows the same steps as almost every scikit-learn project:
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
X, y = load_iris(return_X_y=True) # flower measurements and species
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
model = LogisticRegression(max_iter=200)
model.fit(X_train, y_train) # learn from the training data
predictions = model.predict(X_test) # predict on unseen data
print("Accuracy:", accuracy_score(y_test, predictions))The script prints an accuracy number between 0 and 1. The exact value can depend on your library version, so do not worry if yours is slightly different. The important idea is the pattern:
Load the data into features
Xand targety.Split it so you can test on data the model has never seen.
Create a model and fit it on the training part.
Predict on the test part and score the result.
Why is scikit-learn good for beginners?
One interface. Almost every model has
fitandpredict. SwapLogisticRegressionfor another model and the rest of your code barely changes.Built-in datasets and metrics let you practise without hunting for data.
Clear documentation with examples for each tool.
Skills that transfer. Splitting data, evaluating and avoiding overfitting apply to every kind of ML.
What should you learn after scikit-learn?
Once the load, split, fit and score pattern feels natural, try a second model on the same data and compare scores. Then learn cross-validation, which tests a model on several different splits, and basic feature work. Deep learning libraries come later, and the ideas you practised here, such as train/test splits and overfitting, carry straight over. For the big picture, read how a neural network works.
Common mistakes
Testing on training data. That says nothing about new data. Always hold some data back.
Scaling before splitting. Fit scalers on the training set only, to avoid leaking information.
Chasing accuracy alone. On unbalanced data, accuracy can look high while the model misses the cases you care about. Look at other metrics too.
Skipping the data. Cleaning and feature work usually matter more than the model choice; see the chapter on preparing ML-ready data.
To go step by step, follow the chapter your first machine learning model with scikit-learn.
Key Takeaway
scikit-learn is the standard starting library for classic machine learning in Python. Learn its pattern of load, split, fit, predict and score, and you can try many models with very little code.
Ready to start? You will build your first machine learning model in Python and learn the data skills around it. Begin with the free course Python for AI: From Zero to Your First AI App.
Related articles
More in Python
Python Virtual Environments (venv) Explained
A Python venv keeps each project's packages separate so projects cannot break each other. Learn the exact commands for macOS, Linux and Windows, plus requirements.txt.
5 min readNov 29, 2026Web Scraping With Python: A Beginner's Guide
Learn the basics of web scraping with Python using requests and BeautifulSoup, and the rules that keep you polite and safe: robots.txt, terms of service, rate limits and personal data.
4 min readNov 24, 2026Clean CSV Data With Pandas: 10 Useful Commands
Ten pandas commands that fix most messy CSV files: spaces, capitals, duplicates, wrong types and missing values, shown in one example you can run.
4 min readNov 21, 2026TensorFlow vs PyTorch: Which Should Beginners Learn?
TensorFlow and PyTorch teach the same core ideas. Compare them for beginners, see what they automate with a small runnable Python example, and learn how to choose without wasting weeks.
4 min readNov 19, 2026Jupyter vs VS Code vs Google Colab
Where should you write your first Python code? Compare Jupyter Notebook, VS Code and Google Colab, with a simple rule for choosing.
4 min readNov 15, 2026Your First Python Project: Build a Calculator
Build a command-line calculator in about 30 lines of Python, learning functions, loops, conditions and error handling along the way.
3 min readNov 12, 2026
Comments
Sign in to join the discussion.

