Use a Python virtual environment and scikit-learn for your first machine learning setup. Verify the installation with a tiny synthetic dataset before downloading a large one.
What you need
- Python, a terminal and editor
- A virtual environment
- scikit-learn and its installed dependencies
Set up your environment
- Install Python 3.12 for a conservative starting point, then create a practice folder. Check the current scikit-learn requirements if selecting another Python version.
- Run
python -m venv .venv. The commands below use the Windows virtual-environment interpreter directly, so activation is optional. - Run
.venv\Scripts\python.exe -m pip install --upgrade pip, then.venv\Scripts\python.exe -m pip install scikit-learn. - Save the example as check_ml.py. On Linux/macOS replace the interpreter path with
.venv/bin/python.
Your first check
Save as check_ml.py
from sklearn.linear_model import LinearRegression
model = LinearRegression().fit([[1], [2], [3]], [2, 4, 6])
prediction = model.predict([[4]])
print(round(float(prediction[0]), 1))Run or verify
.venv\Scripts\python.exe check_ml.pyExpected result: 8.0 is printed. This verifies the toolchain, not the usefulness of a real-world model.
Common setup problems
- If sklearn cannot be imported, install scikit-learn with the same interpreter used to run the file.
- Do not name your file sklearn.py or numpy.py; those names can shadow installed libraries.
Official documentation
Guide reviewed 17 November 2026. Check the linked vendor documentation for current supported versions and operating systems.