Giter VIP home page Giter VIP logo

clustring's Introduction

Automatic Clustering of Coordinates

Selection Number of Clusters Using BIC Score from GMM

This project demonstrates a method to automatically choose the number of clusters for clustering geographical coordinates using Gaussian Mixture Models (GMM) and K-means algorithm. It provides visualizations of the cluster distribution and cluster visualization on a map.

Requirements

  • pandas
  • matplotlib
  • scikit-learn
  • numpy
  • scipy

Usage

  1. Ensure that the coordinates.pkl file is present in the same directory as the code file.

  2. Run the code to perform clustering on the coordinates.

  3. The method will automatically select the optimal number of clusters based on Bayesian Information Criterion (BIC).

  4. The resulting clusters will be added to the coordinates dataframe.

  5. The number of clusters will be displayed.

  6. The distribution of clusters will be plotted in a bar chart.

  7. The clusters will be visualized on a map.

References

  1. https://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html
  2. https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html
  3. https://www.datacamp.com/tutorial/k-means-clustering-python

Example

# Load the coordinates data from the pickle file
coordinates = pd.read_pickle('coordinates.pkl')

# Cluster the coordinates and automatically choose the number of clusters
coordinates, num_clusters = cluster_coordinates(coordinates)

# Display the number of clusters
print(f"Number of clusters: {num_clusters}")

# Plot the distribution of clusters
cluster_counts = coordinates['cluster'].value_counts()
plt.figure(figsize=(10, 6))
cluster_counts.plot(kind='bar')
plt.xlabel('Cluster')
plt.ylabel('Frequency')
plt.title('Distribution of Clusters')
plt.show()

# Visualize the clusters on a map
colors = ['green', 'blue', 'red', 'yellow']
plt.figure(figsize=(8, 8))
for cluster_id in range(num_clusters):
    cluster_points = coordinates[coordinates['cluster'] == cluster_id]
    plt.scatter(cluster_points['Composite:GPSLongitude'], 
                cluster_points['Composite:GPSLatitude'],
                color=colors[cluster_id], label=f'Cluster {cluster_id}')

plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('Cluster Visualization')
plt.legend()
plt.grid(True)
plt.show()

clustring's People

Contributors

aimad1234 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.