Skip to content

An Implementation of fuzzy clustering algorithms in Numpy

License

Notifications You must be signed in to change notification settings

Samxx97/Fuzzy-Clustering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fuzzy Clustering

📖 Description

a Numpy vectorized implementation written in Python of some of the fuzzy clustering algorithms, it includes the following:

  • ➤ Fuzzy C-Means
  • ➤ Gustafason-Kessel

Theoritical General Description of the Fuzzy Algorithm

Fuzzy Clustering is a form of clustering in which each data point can belong to more than one cluster it involves assigning data points to clusters such that items in the same cluster are as similar as possible while items belonging to different clusters are as dissimiliar as possible. Clusters are identified via similarity measures. Different similarity measures may be used, in this implementation the euclidean distance and Mahalanobis distance are used.

Comparison to hard Clustering

in non-fuzzy clustering, data is divided into distinct clusters, where each data point can only belong to exactly one cluster. In Fuzzy clustering, data points can potentially belong to multiple clusters.

The Algorithm:

  1. Initialize Membership Matrix such that values across each center sum to 1
  2. Update the Class Centers Matrix
  3. Calculate the distances of samples from Class Centers
  4. Update Memberships
  5. Repeat step number 2 Until Convergence or reaching maximum number of iterations allowed

💾 How to Install

before installing the package its highly recommended that you create a virtual environment, there are many tools which are capable of that, such as conda , venv ...etc. here is an example of doing so using virtualenv:

First you install virtualenv

$ pip install virtualenv 

Then create a folder where you can create your environment and cd into it and then execute the following command:

$ virtualenv env 

Now activate the environment

$ \env\Scripts\activate.bat 

To Install the Package from PyPi, install pip then run the following code:

$ pip install Fuzzy_Clustering 

OR if you want to also include dependencies which are necessery for running the examples, you must run the following:(Recommended)

$ pip install Fuzzy_Clustering[examples] 

📝 Usage

You can clone the repository and check into the examples folder, it provides two examples.

The first example demonstrates how one can use fuzzy clustering to segment the color values within an into several distinct groups, in the example below,Fuzzy C-Means was used with a parameterof 10 clusters.

$ python fuzzy_image_segmentation.py 

segmentation results

The second example demonstrates the results of running the algorithm on a set of random scattered data points, the algorithm was run several times with a varying number of clusters parameter.

$ python random_data_clustering.py 

random points clustering

Releases

No releases published

Packages

No packages published

Languages