<jupyter_start><jupyter_text>Clustering comparative analysis**Original code**: [<NAME>](https://github.com/akorkovelos)**Conceptualization & Methodological review** : [<NAME>](https://github.com/akorkovelos)**Updates, Modifications**: [<NAME>](https://github.com/akorkovelos)  Importing packages<jupyter_code># Operational
import os
import tkinter as tk
from tkinter import filedialog, messagebox
root = tk.Tk()
root.withdraw()
root.attributes("-topmost", True)

# Numerical
import geopandas as gpd
import pandas as pd
import numpy as np
import math

# Mapping
import contextily as ctx
from ipyleaflet import *

# Graphs and plotting
import seaborn as sns

import matplotlib.pyplot as plt
%matplotlib inline
# Coordinate system in EPSG registry
proj_crs = "epsg:32736"
def_crs = "epsg:4326"<jupyter_output><empty_output><jupyter_text>Import & prepare building footprint dataset  Importing dataset<jupyter_code># Define path and name of the geometry file
path = r"C:\Users\alexl\Dropbox\Self-employment\WBG\Work\GEP\clustering_process\DBSCAN_Clustering\Sample_Output"
path_KTH = r"C:\Users\alexl\Dropbox\Self-employment\WBG\Work\GEP\clustering_process\DBSCAN_Clustering\Sample_Input"

name_shp_HDBSCAN_self = "Sample_Concave_clustered_buildings_HDBSCAN_self_tuned.shp"
name_shp_HDBSCAN_auto = "Sample_Concave_clustered_buildings_HDBSCAN_auto_tuned.shp"
name_shp_DBSCAN = "Sample_Concave_clustered_buildings_DBSCAN.shp"
name_shp_True = "Sample_Concave_clustered_buildings_true.shp"
name_shp_KTH = "Kisoro_KTH_clusters.gpkg"
# Create a new geo-dataframe(s)
geom_gdf_HDBSCAN_self = gpd.read_file(path + "\\" + name_shp_HDBSCAN_self)
geom_gdf_HDBSCAN_auto = gpd.read_file(path + "\\" + name_shp_HDBSCAN_auto)
geom_gdf_DBSCAN = gpd.read_file(path + "\\" + name_shp_DBSCAN)
geom_gdf_True = gpd.read_file(path + "\\" + name_shp_True)
geom_gdf_KTH = gpd.read_file(path_KTH + "\\" + name_shp_KTH)
m = Map(
    basemap=basemap_to_tiles(basemaps.OpenStreetMap.HOT),
    center=(buildings.geometry.centroid[0].y, buildings.geometry.centroid[0].x),
    zoom=13)

building_data = GeoData(geo_dataframe = buildings,
                       style={'color': 'black', 'opacity':3, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                       hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                       name = 'Buildings')

DBSCAN_geom = GeoData(geo_dataframe = geom_gdf_DBSCAN,
                     style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                     hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                     name = 'DBSCAN')

HDBSCAN_geom_self = GeoData(geo_dataframe = geom_gdf_HDBSCAN_self,
                     style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                     hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                     name = 'HDBSCAN self-tuned')

HDBSCAN_geom_auto = GeoData(geo_dataframe = geom_gdf_HDBSCAN_auto,
                     style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                     hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                     name = 'HDBSCAN auto-tuned')

KTH_geom = GeoData(geo_dataframe = geom_gdf_KTH,
                   style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                   hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                   name = 'KTH clusters')

true_geom = GeoData(geo_dataframe = geom_gdf_True,
                     style={'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                     hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},
                     name = 'true geometries')

m.add_layer(building_data)
m.add_layer(HDBSCAN_geom_self)
m.add_layer(HDBSCAN_geom_auto)
m.add_layer(DBSCAN_geom)
m.add_layer(KTH_geom)
m.add_layer(true_geom)

m.add_control(LayersControl())

m<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14520415559313843, 'fraction_numerical': 0.021985986953370378, 'mean_word_length': 4.117428924598269, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '496755', 'license': 'MIT', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1546, 'n_words': 239, 'path': 'Comparative_analysis.ipynb', 'repo_name': 'akorkovelos/HDBSCAN-Building-Clustering', 'size': '4184'}