Importing Data with Scikit-Learn

There are three main ways to obtain data when using scikit-learn:

  • Using the toy datasets that come with it.

  • Generating synthetic data.

  • Importing data from external sources, such as CSV files.

Loading toy datasets from scikit-learn

The scikit-learn library provides several toy datasets that we can use for experimenting with ML algorithms. One of the most commonly used datasets is the iris dataset, which contains information about iris flowers, including their sepal length and width, petal length and width, and species. This is a classic toy dataset, often used in tutorials due to its data is relatively clean, and it can be used for multiclass classification tasks.

The following code demonstrates how to load the iris dataset into our Python environment and plot it:

Get hands-on with 1400+ tech skills courses.