Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 40 ยท Getting Started

What Is scikit-learn?

Meet scikit-learn, Python's standard library for classical machine learning: what it covers, what it leaves out, how to install it and how its parts fit together.

scikit-learn (imported as sklearn) is the most widely used Python library for classical machine learning: models that learn from tabular data such as spreadsheets and database tables. It gives you dozens of algorithms for predicting numbers, predicting categories, grouping similar rows and shrinking wide tables, all behind one consistent interface. Learn that interface once and every algorithm feels familiar.

It is built on NumPy, SciPy and joblib, and it works smoothly with pandas and Matplotlib. If you are new to the ideas behind it, What Is Machine Learning? is a good companion. This course focuses on the library itself.

What scikit-learn covers

Six jobs scikit-learn does well

Regression Predict a number.
Classification Predict a category.
Clustering Find groups without labels.
Dimensionality reduction Fewer columns, same story.

Each family has many algorithms with the same fit and predict methods.

1 / 2

What it does not cover

scikit-learn does not train deep neural networks on GPUs, process images or text with large pretrained models, or run on a cluster. For those, use PyTorch or TensorFlow and Keras. It also has no built-in reinforcement learning. For tables with up to a few million rows, though, it is usually the fastest route to a strong, understandable model.

Installing

On your own computer:

Terminal
pip install scikit-learn

The package is called scikit-learn, but you import it as sklearn. Every TryIt in this course runs scikit-learn in your browser, so you can follow along without installing anything.

Python Check the installation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

How the library is organised

Everything lives in sub-modules, and you import only what you need:

Module What it holds Example
sklearn.datasets Toy datasets and data generators load_iris
sklearn.preprocessing Scalers and encoders StandardScaler
sklearn.impute Missing-value fillers SimpleImputer
sklearn.linear_model Linear and logistic regression LinearRegression
sklearn.tree, sklearn.ensemble Trees, forests, boosting RandomForestClassifier
sklearn.cluster Clustering KMeans
sklearn.model_selection Splits, cross-validation, search train_test_split
sklearn.metrics Scores accuracy_score
sklearn.pipeline Chaining steps Pipeline

A good habit is to import classes directly, as in from sklearn.linear_model import LinearRegression, rather than importing the whole package.

A five-line taste

Here is a complete machine-learning program. It learns to recognise iris flowers from four measurements and then predicts the species of the first flower.

Python Learn, then predict

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You will study each piece in the coming lessons: your first model, datasets and the estimator API.

The big idea: one interface

Every model you meet here follows the same pattern, which is why this library is easy to learn:

flowchart LR
    A["Create the object<br/>model = Algorithm(settings)"] --> B["Learn from data<br/>model.fit(X, y)"]
    B --> C["Use it<br/>model.predict(X_new)"]
    C --> D["Judge it<br/>model.score(X_test, y_test)"]

Swap the algorithm and the other three steps stay the same.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the correct import name for the scikit-learn package?

    The package installs as scikit-learn but is imported as sklearn.
  2. 2. Which task is NOT a good fit for scikit-learn?

    scikit-learn is built for classical machine learning on tabular data. Large deep-learning models belong in PyTorch or TensorFlow.
  3. 3. Why is scikit-learn easy to learn across many algorithms?

    A consistent API means that changing the algorithm usually changes one line.
  4. 4. Which sub-module contains train_test_split?

    Splitting, cross-validation and hyperparameter search live in sklearn.model_selection.

Summary

  • scikit-learn is Python's standard library for classical machine learning on tabular data.
  • It covers regression, classification, clustering, dimensionality reduction, preprocessing, model selection and metrics.
  • It is not a deep-learning framework.
  • Install with pip install scikit-learn, import as sklearn.
  • All models share one interface, so learning one teaches you all.

Next: Your First Model