Setting Up a Machine Learning Development Environment on Mac

March 15, 2025 | By touch@creative-moon.com
Setting Up a Machine Learning Development Environment on Mac-thumb-nail


Setting up a proper development environment is the first step toward machine learning proficiency. This guide covers installing Python, setting up a virtual environment, and configuring essential libraries for machine learning on a MacBook Air M4. Additionally, it includes instructions for running Jupyter Notebook and a simple linear regression experiment to verify the setup. By the end of this guide, you will have a fully functional environment to begin your machine learning projects.


Goal: Set up a Python development environment for machine learning on a MacBook Air M4 and run the first machine learning experiment in Jupyter Notebook.


1. Installing Python and Development Tools

Install Homebrew (Mac Package Manager)

Homebrew helps manage packages easily on macOS.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Verify the installation:

brew --version

Install Python (Using Pyenv)

macOS comes with Python pre-installed, but managing multiple versions is easier with pyenv.

brew install pyenv
pyenv install 3.11.11
pyenv global 3.11.11

Verify the installation:

python --version

2. Setting Up the Machine Learning Environment

Create and Activate a Virtual Environment

To keep projects isolated, use venv.

python -m venv ml_env
source ml_env/bin/activate  # For Windows: ml_env\Scripts\activate

Check if the virtual environment is activated:

which python

If the output points to ml_env/bin/python, the environment is set up correctly.

Install Essential Machine Learning Packages

Install the necessary libraries for machine learning.

pip install numpy pandas matplotlib seaborn scikit-learn jupyter

Verify the installation:

pip list

3. Running Jupyter Notebook

After setting up the environment, launch Jupyter Notebook.

jupyter notebook

Once running, open the browser and go to http://localhost:8888/tree.


4. First Machine Learning Experiment: Linear Regression

To verify that everything is working, implement a simple linear regression model.

Python Code:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LinearRegression

# Generate data
x = np.array([1, 2, 3, 4, 5]).reshape(-1, 1)
y = np.array([2, 4, 6, 8, 10])

# Train a linear regression model
model = LinearRegression()
model.fit(x, y)

# Predict and visualize results
y_pred = model.predict(x)
plt.scatter(x, y, color='blue', label='Actual')
plt.plot(x, y_pred, color='red', label='Predicted')
plt.legend()
plt.show()

Output:

• Blue dots (Actual) represent real data points

• Red line (Predicted) represents the model’s predictions

• The regression model successfully fits the data


5. Summary and Next Steps

Key Takeaways

• Installed Python 3.11.11 and set up the development environment

• Created a virtual environment and installed necessary machine learning libraries

• Ran Jupyter Notebook and executed the first machine learning model

Next Goal: Start the First Portfolio Project

House Price Prediction Project (Using Canadian Real Estate Data)

• Collect and preprocess data

• Build and evaluate a machine learning model


Additional Notes

Jupyter Notebook Shortcuts

• Shift + Enter → Run the current cell and move to the next

• Esc + B → Add a new cell

• Esc + M → Convert a cell to Markdown mode (for writing explanations)

This marks the first step toward becoming a machine learning engineer. I will continue learning and building portfolio projects to prepare for job applications.