Online Tutorial -- Learning not just technology, but also dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
Sklearn Installation
Sklearn Tutorial Sklearn Introduction Sklearn Installation Sklearn Basics Sklearn Data Preprocessing Sklearn Machine Learning Models Sklearn Model Evaluation and Tuning Sklearn Pipeline Sklearn Custom Models and Functions Sklearn Model Saving and Loading Sklearn Application Cases Sklearn House Price Prediction Sklearn Introduction Sklearn BasicsSklearn Installation
To learn Sklearn, installation is the first step. Since Sklearn depends on several other libraries (such as NumPy, SciPy, and matplotlib), we need to ensure these dependencies are also installed.
System Requirements:
- Python Version: scikit-learn supports Python 3.7 and above.
- Operating System: scikit-learn can run on mainstream operating systems such as Windows, macOS, and Linux.
- Package Manager: You can use
piporcondato install scikit-learn.
In this section, we will use pip to install scikit-learn.
Before installation, ensure Python and pip are installed.
Check Python installation:
python --version
Check pip installation:
pip --version
If Python and pip are not installed, refer to our Python Installation and Pip Installation.
Note: The latest Python versions come with pip pre-installed.
Note: Python 2.7.9+ or Python 3.4+ versions come with pip included.
Install Sklearn
Sklearn is short for scikit-learn.
Use pip to install the latest version of scikit-learn:
pip install scikit-learn
If you want to install a specific version of scikit-learn, specify the version number:
pip install scikit-learn==1.2.0
Check Installation Success
After installation, you can check if scikit-learn is installed successfully with the following code:
Example
import sklearn
print(sklearn.__version__)
If the version number of scikit-learn is displayed successfully, similar to the following, it means the installation was successful:
1.5.2
Install scikit-learn with conda
If you are using the Anaconda environment, it is recommended to use conda to install scikit-learn.
Anaconda is a Python distribution for scientific computing that includes many data science and machine learning libraries, making it convenient for developers.
If you are not familiar with Anaconda, refer to: Anaconda Tutorial.
Create a new conda environment (optional)
You can create a new virtual environment for scikit-learn to avoid conflicts with other projects:
conda create -n sklearn-env python=3.9
conda activate sklearn-env
Install scikit-learn
Use conda to install scikit-learn:
conda install scikit-learn
If you want to install a specific version, specify the version number:
conda install scikit-learn=1.2.0
Verify Installation
In the conda environment, you can verify the installation via Python shell or Jupyter Notebook:
Example
import sklearn
print(sklearn.__version__)
If the version number of scikit-learn is displayed successfully, similar to the following, it means the installation was successful:
1.5.2
Install Other Dependencies
scikit-learn depends on several other libraries, especially:
- NumPy: For array processing and numerical computations
- SciPy: Provides advanced mathematical computation tools
- matplotlib (optional): For data visualization
- joblib (optional): For model persistence (saving and loading)
If you use pip to install, scikit-learn will automatically install these dependencies. However, if you want to manually install or update them, use the following commands:
pip install numpy scipy matplotlib joblib
When using conda, all dependencies will be installed automatically.
YouTip