
Build a full-stack gis earthquake forecasting map using Python and Leaflet, from data analysis and machine learning modeling to visualization of predictions on interactive maps.
Install Python 3.7, create a project folder and an application folder, add Python to your environment variables, and verify the installation by running python --version.
Create a portable Python project by upgrading pip, installing virtualenv, and building a virtual environment, then activate it to manage libraries and deactivate when finished.
Activate a virtual environment and install Django and libraries—Django tool belt, Django GeoJSON, Django Leaflet, and pandas—to build a Django-based predictive maps app, create geo quakes project and app.
Download and install Visual Studio Code, then install Python extension for syntax highlighting and auto completion. Open the project folder, activate the virtual environment, and run Django server on localhost:8000.
Install PostgreSQL database server, select extensions such as PGA agent and database drivers, then create a quake database in pgAdmin and verify connections with a dashboard.
Update the Django settings: add geo quakes to installed apps, set postgres as the database (quake, postgres, localhost, 5432), and enable geojson serialization and static files paths.
Create a Django model named quake with fields for date, latitude, longitude, type, depth, magnitude, and magnitude type; Django converts it to a Postgres table via migrations.
This lecture demonstrates adding the admin.py code to register the quake model, load a csv dataset from GitHub, clean with pandas, and insert records into Postgres.
Learn to build the Django front end by creating templates folders, index.html and layout.html, and a static directory with CSS, JavaScript, and leaflet.js for maps.
Create Django views that query quake data from a Postgres model, serialize results to json, and return a json response, optionally rendering templates or using ajax for the front end.
Define url patterns in a Django app to expose the quake dataset via a REST API for map visualization with Leaflet.
Add an index.html that inherits the site layout, defines a block content, and loads static assets so the page shares the app’s layout and resources.
Learn to add a layout.html base with doctype, head meta, and static CSS/JS, using Django templating to inject title and content for a Leaflet map page with a side menu.
Create your first map using Leaflet by importing Leaflet assets, styling the map to fit the screen, and initializing a default Open Street Map base map with a set view.
Add markers to a map by fetching earthquake data via json API, then loop through records to plot markers with latitude, longitude, and magnitude in a Leaflet popup on OpenStreetMap.
Install python 3.7 64-bit, set up a virtual environment, and install pandas and a data science library. Open jupyter notebook, create a new python 3 notebook, and start writing code.
Perform data pre-processing on earthquake data by cleaning, renaming columns, and selecting latitude, longitude, magnitude, and depth to prepare features and train-test splits for evaluation.
Select a random forest regression model, train with X_train and y_train, validate on X_test with accuracy, then optimize via grid search CV to boost performance and test on out-of-sample data.
Build a prediction dataset from the best-fit model, extract magnitude and depth into separate lists, create a data frame, and prepare for productionizing the model.
Create a Django model for quake predictions with latitude, longitude, magnitude, depth, and a float field, and set its verbose name. Run makemigrations and migrate to create the Postgres table.
Embed a machine learning pipeline into the app by importing ml libraries, preparing training and test data, training a random forest model with grid search, and generating quake prediction outputs.
Create a second API endpoint for the quake prediction data, serialize the dataset to JSON, query the first thousand records, and expose it as the quake data endpoint.
Add a layers control to switch between multiple base maps and initialize base layers for open street map, world ocean base, world street map, and world imagery.
Create a marker layer group to cluster markers, bind popups showing magnitude, enable hover to open and close popups, and add the markers as an overlay in the layers control.
Add a point layer group to plot circle markers on a Leaflet map, size by earthquake magnitude, with popups and a layer control to toggle points and overlays.
Add a predicted quakes point layer group by fetching the predicted earthquakes dataset, rendering yellow circle markers on the map, and exposing an overlay named 'predicted quakes for 2017'.
Create a predicted high risk quake layer by querying magnitudes greater than 6.5, render red circle markers in a Leaflet layer group, and add a high risk quakes overlay.
Create and customize a leaflet map legend to describe earthquake data, including 1965–2016 markers plus 2017 predicted and high-risk earthquakes.
Create a prediction score legend on the map to display earthquake forecast accuracy. Fetch the score from the database and render it in a top-right overlay with two-decimal precision.
Welcome to the Machine Learning for Predictive Maps in Python and Leaflet course.
In this course we will be building a earthquake forecasting map application,
by using a variety of independent tools and then integrate them to produce a full stack web gis application.
We will be writing code in multiple programming languages, which gives us experience
with different stacks of an application and different tools.
We will be covering various topics ranging from web gis, python programming, data analysis,
machine learning and geo data visualization. All of our development will be done on windows 10.
You will learn how to build a full stack web gis application
You will learn how to build predictive models
You will learn how to build a prediction engine that's embedded in the application
You will learn how to build and automate a machine learning pipeline
You will learn how to use multiple basesmaps and layers
You will learn programming in leaflet.js
You will learn how to create REST API endpoints and call them with Ajax and JQUERY
You will learn how to use the Django template engine to pass data from the back-end to the front-end of the application
You will learn how to integrate a PostgreSQL database with Django
You will also learn how to visualize data on a map