TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Follow publication

Member-only story

Introduction to Mesa: Agent-based Modeling in Python

Python-based alternative to NetLogo, Repast, or MASON for agent-based modeling

Simulation result showing segregation between blue and red agent

Agent-based modeling relies on simulating the actions and interactions of autonomous agents to evaluate their effects on the system. It is often used to predict the projections that we will obtain given a complex phenomena. The main purpose is to obtain explanatory insight on how the agents will behave given a particular set of rules. Agent-based modeling has been extensively used in numerous industry such as biology, social sciences, network and business. This article covers the necessary steps to kick-start your agent-based modeling project using an open-source python module called Mesa. There are 4 sections in this tutorial:

  1. Setup
  2. Schelling Segregation Model
  3. Visualization
  4. Conclusion

1. Setup

Setup is pretty straightforward for Mesa. Make sure to create a new virtual environment. I name the environment as mesaenv. Open up your terminal and change the directory to mesaenv and activate the virtual environment using the following code:

Virtual Environment

Run the following command to activate the virtual environment depending on your use case.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Ng Wai Foong

Written by Ng Wai Foong

Senior AI Engineer@Yoozoo | Content Writer #NLP #datascience #programming #machinelearning | Linkedin: https://www.linkedin.com/in/wai-foong-ng-694619185/

Responses (3)

Hello. Any suggestions on online communities for the mesa framework? I've been looking for a Discord server, for instance, but can't seem to find anything.

Hi - the model.py and server.py files are much larger in github than the ones you show here. what am i missing ?

Good day sir, how can make the initial positions of each agent permanent so that when I reset I just get the same initial positions for each of the agents. Another way to say it is I want uniform initial conditions for every time I hit reset…