Since the majority of these tutorias are based on scikit-learn this tutorial covers the installation of the scikig-learn library. Installign scikit-learn, a powerful Python library for ML, is a strightforward process, and it can be done using several methods depending on your operating system and preferences. In this guid we will explore all the common ways to install scikit-learn, ensuring that you can set it up easily in you environment.
The most common and recommended way to install scikit-learn is via pip, the Python package installer. Open your terminal or command prompt and run the following command:
If you are using Anaconda or Miniconda, you can install scikit-learn using the conda package manager. Run the following command:
The advanced users who want to customize or explore the library source code installing the scikit-learn from source is a good option. However, before isntalling the scikit-learn from source you have to install or at least check the following:
Using pip
The most common and recommended way to install scikit-learn is via pip, the Python package installer. Open your terminal or command prompt and run the following command:
pip install scikit-learnThis will download and install the latest version of scikit-learn along with its dependencies. If you want to install a specific version, you can specify it like this:
pip install scikit-learn==1.3.0To upgrade an exisiting installation use:
pip install --upgrade scikit-learn
Using Conda
If you are using Anaconda or Miniconda, you can install scikit-learn using the conda package manager. Run the following command:
conda install -c conda-forge scikit-learnThe -c conda-forge flag ensures you are using the Conda-Forge channel, which often has the most up-to-date packages. Alternatively, you can install from the default channel:
conda install scikit-learnThis method is particularly useful for handling dependencies efficiently, especially in scientific computing environments.
Installing from source
The advanced users who want to customize or explore the library source code installing the scikit-learn from source is a good option. However, before isntalling the scikit-learn from source you have to install or at least check the following:
- Is Python installed?
- Is pip ready and updated?
- Is setuptools and wheel ready and updated? If not type in the following:
pip install --upgrade setuptools wheel
- Cython - you need to install it to compile .pyx files.
pip install --upgrade cython
- Numpy and SciPy (needed for building scikit-learn
pip install numpy scipy
sudo apt-get install build-essentialOn macOS install Xcode command-line tools.
xcode-select --installOn Windows operating system install C++ compiler, such as Microsoft C++ Build Tools or MinGW-w64. The first step in this process is to clone the repository from GitHub:
git clone https://github.com/scikit-learn/scikit-learn.gitAfter the repository is cloned you need to navigate to the code where library is cloned and install the library:
cd scikit-learnThe pip command will install the scikit-learn library from the source directory. Additionally you can check if scikit-learn is installed and working:
pip install .
python -c "import sklearn; print(sklearn.__version__)"