{"id":26562823,"url":"https://github.com/centrogeo/hierarchicalgeoclustering","last_synced_at":"2025-03-22T15:28:55.738Z","repository":{"id":38797727,"uuid":"433629000","full_name":"CentroGeo/HierarchicalGeoClustering","owner":"CentroGeo","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-27T00:41:34.000Z","size":11223,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-27T01:19:28.757Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CentroGeo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-01T00:18:16.000Z","updated_at":"2025-02-27T00:41:38.000Z","dependencies_parsed_at":"2025-02-27T01:19:04.589Z","dependency_job_id":"7f3cf52b-64c6-491d-9835-a05ff2050962","html_url":"https://github.com/CentroGeo/HierarchicalGeoClustering","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"fastai/nbdev_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CentroGeo%2FHierarchicalGeoClustering","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CentroGeo%2FHierarchicalGeoClustering/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CentroGeo%2FHierarchicalGeoClustering/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CentroGeo%2FHierarchicalGeoClustering/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CentroGeo","download_url":"https://codeload.github.com/CentroGeo/HierarchicalGeoClustering/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244977601,"owners_count":20541696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-22T15:28:55.149Z","updated_at":"2025-03-22T15:28:55.732Z","avatar_url":"https://github.com/CentroGeo.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"Hierarchical Geo Clustering\n================\n\n\u003c!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --\u003e\n\n## Install\n\nThe library uses the cgal library, if the library is use inside a conda\nenviroment the installation procedure should create the enviroment and\ninstall the cgal library using `conda install -c conda-forge cgal`.\n\nTo install the library can be simply:\n\n`pip install git+https://github.com/CentroGeo/HierarchicalGeoClustering.git`\n\n## How to use\n\n### Build a TreeCluster\n\nWe can build a hierarchical geographical cluster, the `TreeCluster`\nclass allows to create te structure and then populate it.\n\n``` python\nHGC = TreeClusters(3, random_seed= 12)\n```\n\n``` python\nHGC.populate_tree(number_per_cluster=100)\n```\n\n``` python\nHGC.print_structure()\n```\n\n    Root\n    Root    \n    ├── Root_l_0_n_0\n    │   ├── Root_l_0_n_0_l_1_n_0\n    │   │   ├── Root_l_0_n_0_l_1_n_0_l_2_n_0\n    │   │   ├── Root_l_0_n_0_l_1_n_0_l_2_n_1\n    │   │   ├── Root_l_0_n_0_l_1_n_0_l_2_n_2\n    │   │   ├── Root_l_0_n_0_l_1_n_0_l_2_n_3\n    │   │   └── Root_l_0_n_0_l_1_n_0_l_2_n_4\n    │   └── Root_l_0_n_0_l_1_n_1\n    │       ├── Root_l_0_n_0_l_1_n_1_l_2_n_0\n    │       └── Root_l_0_n_0_l_1_n_1_l_2_n_1\n    ├── Root_l_0_n_1\n    │   ├── Root_l_0_n_1_l_1_n_0\n    │   │   └── Root_l_0_n_1_l_1_n_0_l_2_n_0\n    │   ├── Root_l_0_n_1_l_1_n_1\n    │   │   ├── Root_l_0_n_1_l_1_n_1_l_2_n_0\n    │   │   ├── Root_l_0_n_1_l_1_n_1_l_2_n_1\n    │   │   └── Root_l_0_n_1_l_1_n_1_l_2_n_2\n    │   ├── Root_l_0_n_1_l_1_n_2\n    │   ├── Root_l_0_n_1_l_1_n_3\n    │   │   ├── Root_l_0_n_1_l_1_n_3_l_2_n_0\n    │   │   └── Root_l_0_n_1_l_1_n_3_l_2_n_1\n    │   └── Root_l_0_n_1_l_1_n_4\n    │       ├── Root_l_0_n_1_l_1_n_4_l_2_n_0\n    │       ├── Root_l_0_n_1_l_1_n_4_l_2_n_1\n    │       └── Root_l_0_n_1_l_1_n_4_l_2_n_2\n    └── Root_l_0_n_2\n        ├── Root_l_0_n_2_l_1_n_0\n        │   ├── Root_l_0_n_2_l_1_n_0_l_2_n_0\n        │   └── Root_l_0_n_2_l_1_n_0_l_2_n_1\n        ├── Root_l_0_n_2_l_1_n_1\n        │   ├── Root_l_0_n_2_l_1_n_1_l_2_n_0\n        │   ├── Root_l_0_n_2_l_1_n_1_l_2_n_1\n        │   ├── Root_l_0_n_2_l_1_n_1_l_2_n_2\n        │   ├── Root_l_0_n_2_l_1_n_1_l_2_n_3\n        │   └── Root_l_0_n_2_l_1_n_1_l_2_n_4\n        ├── Root_l_0_n_2_l_1_n_2\n        │   ├── Root_l_0_n_2_l_1_n_2_l_2_n_0\n        │   ├── Root_l_0_n_2_l_1_n_2_l_2_n_1\n        │   └── Root_l_0_n_2_l_1_n_2_l_2_n_2\n        └── Root_l_0_n_2_l_1_n_3\n            ├── Root_l_0_n_2_l_1_n_3_l_2_n_0\n            ├── Root_l_0_n_2_l_1_n_3_l_2_n_1\n            ├── Root_l_0_n_2_l_1_n_3_l_2_n_2\n            ├── Root_l_0_n_2_l_1_n_3_l_2_n_3\n            └── Root_l_0_n_2_l_1_n_3_l_2_n_4\n\n``` python\nfig, axs = plt.subplots( figsize=(8,8))\nHGC.visualize(axs, polygon=True)\n```\n\n![](index_files/figure-gfm/cell-5-output-1.png)\n\n``` python\nHGC.root.polygon_cluster\n```\n\n![](index_files/figure-gfm/cell-6-output-1.svg)\n\n``` python\nHGC.get_deepth()\n```\n\n    4\n\n### Extract the points and clusterize\n\nTo clusterize we extract the points and use the clusterize tool\nimplemented in the `Clustering` module\n\n``` python\noriginal_points= HGC.get_points_tree()\nX_2=np.array([[p.x,p.y] for p in original_points])\ndic_points={'points':[X_2], 'parent':''}\n```\n\n``` python\nHGC_adapta_DBSCAN = recursive_clustering_tree(dic_points,\n                                       levels_clustering = 3,\n                                       algorithm = 'adaptative_DBSCAN'\n                                      )\n```\n\n``` python\nfig, axs = plt.subplots( figsize=(8,8))\nHGC_adapta_DBSCAN.visualize(axs, polygon=True)\n```\n\n![](index_files/figure-gfm/cell-10-output-1.png)\n\n### Get the Similarity Shape Measurement\n\nTo obtain the SSM the clusters tree has to be used, this due to the use\nof the geometric shape in the metric. Therefore the polygons of each\ncluster on each level has to be able to compare.\n\n``` python\nform_metric=[]\n\nfor l in range(0, 4):\n    d = { 'Level': l,                              \n        'adaptive DBSCAN':SSM(HGC.levels_nodes[l],\n                            HGC_adapta_DBSCAN.levels_nodes[l])\n        }\n    form_metric.append(d)\n```\n\n``` python\nform_metric\n```\n\n    [{'Level': 0, 'adaptive DBSCAN': 0.6046098496677557},\n     {'Level': 1, 'adaptive DBSCAN': 0.6195370749041116},\n     {'Level': 2, 'adaptive DBSCAN': 0.4080125145736268},\n     {'Level': 3, 'adaptive DBSCAN': 0.22732397098600046}]\n\n``` python\ndf_metric_form = pd.DataFrame(form_metric)\n```\n\n``` python\ndf_metric_form\n```\n\n\u003cdiv\u003e\n\u003cstyle scoped\u003e\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n\u003c/style\u003e\n\u003ctable border=\"1\" class=\"dataframe\"\u003e\n  \u003cthead\u003e\n    \u003ctr style=\"text-align: right;\"\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003eLevel\u003c/th\u003e\n      \u003cth\u003eadaptive DBSCAN\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth\u003e0\u003c/th\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003e0.604610\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e1\u003c/th\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e0.619537\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e2\u003c/th\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003e0.408013\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003e3\u003c/th\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003e0.227324\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\nA detail\n[documentation](https://centrogeo.github.io/HierarchicalGeoClustering/)\nis available\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentrogeo%2Fhierarchicalgeoclustering","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcentrogeo%2Fhierarchicalgeoclustering","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcentrogeo%2Fhierarchicalgeoclustering/lists"}