๐ŸŽฌ
Data Science - Wintersemester 24/25
  • Welcome
  • Whatโ€™s Data Science and How Do I Do It?
    • ๐Ÿ“†Timeline
    • ๐Ÿดโ€โ˜ ๏ธR Overview
      • ๐Ÿ“ฉInstallation
      • ๐Ÿˆโ€โฌ›GitHub Setup
      • ๐Ÿฅ—DataCamp Courses
    • ๐ŸPython Overview
      • ๐Ÿ“ฉInstallation
      • ๐Ÿˆโ€โฌ›GitHub Setup
      • ๐Ÿ“ฆVirtual Environment Setup
      • ๐Ÿฅ—DataCamp Courses
  • Introduction to Your Project
    • About the Project Guide
    • What is this Project About?
  • Exploratory Data Analysis (EDA)
    • Getting started
    • Discovering the Data ๐Ÿ”Ž
      • Initial Exploration Tasks
      • Initial Data Visualization
    • Data Cleaning and Transformation
      • Cleaning the Crime Dataset๐Ÿ‘ฎ๐Ÿผ
      • Cleaning the Weather Dataset๐ŸŒฆ๏ธ
    • Data Visualization
      • Crime Rate Over Time
      • Crime Types
    • Grouping and Merging Data
    • Linear Regression
    • Impress us!
    • Internship Complete!
  • Advanced
    • Introduction
    • K-Means Clustering
      • The Clustering Model
      • Visualize the clusters
    • Impress us!
  • โœ…Exercise Checklist
  • Legal Disclaimer
Powered by GitBook
On this page
  1. Advanced
  2. K-Means Clustering

Visualize the clusters

PreviousThe Clustering ModelNextImpress us!

Last updated 3 months ago

We will use a mapping library or mapping tool to plot the clusters on the map of Los Angeles.

Here it makes sense to define a color pallette (a list of colors) and to use the Cluster number to index over it.

If you open the HTML/PNG file from file explorer/finder, it should look something like this:

After creating the map:

๐Ÿดโ€โ˜ ๏ธ:

On the Plotly website, you will find a bunch of examples. Choose one that you like, but make sure you don't need tokens for it. Your map doesn't have to look exactly like the one shown above.

In order to get a similar figure, use the scattermapbox type with the open street map style.

Please note that the figure from above was made in Python and some things (like the marker) might not be as easily implementable in R. For the marker, you can just choose another color that is not already used by one of the clusters.

If you want a better parity to the Python example, try this task with Leaflet. :)

๐Ÿ:

To create a folium map use the folium.Map class.

For iterating through rows of a pandas dataframe use the iterrows() method and loop over its returned value.

To create circle markers use the folium.CircleMarker class and make sure to add it to the map using add_to(...). You can also use the folium.Marker class similarly for centroids.

To save the interactive map to an HTML file use the save("example.html") method of the folium map. Make sure the filename you choose ends with .html.

You can create the map using (or ).

Plotly
Leaflet