SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
PyClustering: K-Means Tutorial
Pyclustering Library Tutorial
Theme: K-Means
Library Version: 0.8.1
Author: Andrei Novikov
E-Mail: pyclustering@yandex.ru
Agenda
● PyClustering K-Means Features;
● Input format for K-Means;
● Data clustering using K-Means;
● Additional parameters of the algorithm;
● Data clustering result visualization;
● Image segmentation by K-Meas;
PyClustering K-Means Features
● Python implementation based on numpy.
● C/C++ implementation – core library that is supported for
32, 64-bit Windows, Linux.
● K-Means observer to collect information about clustering
process on each iteration.
● K-Means visualizer to display and animate K-Means
specific results.
C/C++ implementation can be used without python if integration with C/C++
project is required. Use sources from „pyclustering/ccore“.
Import K-Means
K-Means algorithm and its features can be imported from
„pyclustering.cluster.kmeans“:
from pyclustering.cluster.kmeans import kmeans
from pyclustering.cluster.kmeans import kmeans_observer
from pyclustering.cluster.kmeans import kmeans_visualizer
Input data format for K-Means
K-Means algorithm uses array_like data format, for
example, list where each element is point that is
represented by coordinates. Here is an example of 1-D
data:
dataset = [ [0.25], [0.43], [1.34], [-0.56] ]
Example of 2-D data:
dataset = [ [0.1, 0.2], [0.1, 0.6], [0.2, -1.4] ]
Example of 3-D data:
dataset = [ [0.6, 0.1, 0.4], [0.2, 0.1, 0.9] ]
Clustering by K-Means algorithm
K-Means uses two general parameters for clustering: input
data and initial cluster centers.
from pyclustering.cluster.kmeans import kmeans
from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer;
from pyclustering.utils import read_sample;
data = [ [0.1], [0.2], [0.5], [0.3], [1.5], [1.8], [1.3], [1.6], [1.5] ]
initial_centers = kmeans_plusplus_initializer(data, 2).initialize()
instance = kmeans(data, initial_centers)
instance.process() # perform processing
clusters = instance.get_clusters(); # allocated clusters
centers = instance.get_centers(); # cluster centers
Output result of K-Means
K-Means algorithm returns allocated clusters and
corresponding centers:
● Clusters are represented by list of clusters and each
cluster contains object indexes from dataset, for example:
[ [0, 1, 4], [2, 3, 5] ], where 0, 1, 4 – object indexes that
forms the first cluster, and 2, 3, 5 – forms the second.
● Centers are represented by list of centers where each
center is a point represented by coordinates.
Library core usage
By default core of pyclustering library that is called „ccore“
used for processing (C/C++ implementation of the
algorithm). If platform is not supported then python
implementation is used. There is special parameter that
can be used to switch on/off core usage:
# switch on core (switch on by default, and it is ignored if impossible to use core
instance = kmeans(data, initial_centers, ccore=True)
# switch off core (python implementation is used instead)
instance = kmeans(data, initial_centers, ccore=False)
K-Means result visualization
Output result can be shown by common visualizer
„cluster_visualizer“ from „pyclustering.cluster“ or by K-
Means visualizer:
instance = kmeans(sample, start_centers, 0.0001)
instance.process()
clusters = instance.get_clusters()
centers = instance.get_centers()
# visualize clustering results
kmeans_visualizer.show_clusters(sample, clusters, centers, start_centers);
Stop condition – tolerance
K-Means calculates center changes on current and
previous iterations and if difference is less than threshold
value defined by parameter „tolerance“ than clustering
process is over.
Example with small data points:
data = [ [0.0000001], [0.00000023], [0.00000051], [0.0000002] ]
tolerance = 0.000000001
instance = kmeans(data, initial_centers, tolerance)
But in case of very big or very small data values
normalization should be used.
K-Means visualizer
Output result can be shown by common visualizer
„cluster_visualizer“ from „pyclustering.cluster“ or by K-
Means visualizer:
instance = kmeans(sample, start_centers, 0.0001)
instance.process()
clusters = instance.get_clusters()
centers = instance.get_centers()
# visualize clustering results
kmeans_visualizer.show_clusters(sample, clusters, centers, start_centers);
Example of result visualization
Here several examples of K-Means visualization:
K-Means result animation
K-Means clustering process can be visualized as an
animation and saved to file. „kmeans_observer“ is used to
collect information of each step of processing and the
observer is used by „kmeans_visualizer“ then.
observer = kmeans_visualizer()
instance = kmeans(data, start_centers, observer=observer)
instance.process()
# animate clustering process
kmeans_visualizer.animate_cluster_allocation(sample, observer);
# or save animation to file
kmeans_visualizer.animate_cluster_allocation(data, observer, save_movie=file.mp4);
K-Means for segmentation
K-Means can consider image as a data where each point
represent pixel with three coordinate (RGB), or with four
coordinate (RGBA). Here is an example of image
segmentation using K-Means algorithm:
from pyclustering.utils import draw_image_mask_segments, read_image
from pyclustering.cluster.kmeans import kmeans;
data = read_image(file_path_to_image);
kmeans_instance = kmeans(data, start_centers);
kmeans_instance.process();
clusters = kmeans_instance.get_clusters();
draw_image_mask_segments(source, clusters);
Image segmentation results
Here several examples of image segmentation by K-
Means algorithm using pyclustering.
References and Links
● Official pyclustering github repository:
https://github.com/annoviko/pyclustering
● Official pypi pyclustering page:
https://pypi.python.org/pypi/pyclustering/0.8.0
● Official pyclustering web-site:
https://pyclustering.github.io/
Thank you for your attention
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Simplilearn
 

Was ist angesagt? (20)

査読コメントに回答する時の、3つの黄金律
査読コメントに回答する時の、3つの黄金律査読コメントに回答する時の、3つの黄金律
査読コメントに回答する時の、3つの黄金律
 
CART: Not only Classification and Regression Trees
CART: Not only Classification and Regression TreesCART: Not only Classification and Regression Trees
CART: Not only Classification and Regression Trees
 
Adversarial machine learning
Adversarial machine learningAdversarial machine learning
Adversarial machine learning
 
Uncertainty Quantification with Unsupervised Deep learning and Multi Agent Sy...
Uncertainty Quantification with Unsupervised Deep learning and Multi Agent Sy...Uncertainty Quantification with Unsupervised Deep learning and Multi Agent Sy...
Uncertainty Quantification with Unsupervised Deep learning and Multi Agent Sy...
 
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
 
Lung Cancer Detection using transfer learning.pptx.pdf
Lung Cancer Detection using transfer learning.pptx.pdfLung Cancer Detection using transfer learning.pptx.pdf
Lung Cancer Detection using transfer learning.pptx.pdf
 
機械学習システムの33のアーキテクチャパターンおよびデザインパターン
機械学習システムの33のアーキテクチャパターンおよびデザインパターン機械学習システムの33のアーキテクチャパターンおよびデザインパターン
機械学習システムの33のアーキテクチャパターンおよびデザインパターン
 
Unsupervised learning (clustering)
Unsupervised learning (clustering)Unsupervised learning (clustering)
Unsupervised learning (clustering)
 
Machine Learning With Logistic Regression
Machine Learning  With Logistic RegressionMachine Learning  With Logistic Regression
Machine Learning With Logistic Regression
 
Kaggle M5 Forecasting (日本語)
Kaggle M5 Forecasting (日本語)Kaggle M5 Forecasting (日本語)
Kaggle M5 Forecasting (日本語)
 
Chapter 10. Cluster Analysis Basic Concepts and Methods.ppt
Chapter 10. Cluster Analysis Basic Concepts and Methods.pptChapter 10. Cluster Analysis Basic Concepts and Methods.ppt
Chapter 10. Cluster Analysis Basic Concepts and Methods.ppt
 
Master's Thesis Presentation
Master's Thesis PresentationMaster's Thesis Presentation
Master's Thesis Presentation
 
Random forest algorithm
Random forest algorithmRandom forest algorithm
Random forest algorithm
 
「傾向スコア分析」 報告事例
「傾向スコア分析」 報告事例「傾向スコア分析」 報告事例
「傾向スコア分析」 報告事例
 
Birch Algorithm With Solved Example
Birch Algorithm With Solved ExampleBirch Algorithm With Solved Example
Birch Algorithm With Solved Example
 
Chapter 09 classification advanced
Chapter 09 classification advancedChapter 09 classification advanced
Chapter 09 classification advanced
 
心理学研究におけるQualtricsの活用
心理学研究におけるQualtricsの活用心理学研究におけるQualtricsの活用
心理学研究におけるQualtricsの活用
 
Density Based Clustering
Density Based ClusteringDensity Based Clustering
Density Based Clustering
 
関数データ解析の概要とその方法
関数データ解析の概要とその方法関数データ解析の概要とその方法
関数データ解析の概要とその方法
 
Probabilistic Programming: Why, What, How, When?
Probabilistic Programming: Why, What, How, When?Probabilistic Programming: Why, What, How, When?
Probabilistic Programming: Why, What, How, When?
 

Ähnlich wie Pyclustering tutorial - K-means

Ähnlich wie Pyclustering tutorial - K-means (20)

Unsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at ScaleUnsupervised Aspect Based Sentiment Analysis at Scale
Unsupervised Aspect Based Sentiment Analysis at Scale
 
Lab 2: Classification and Regression Prediction Models, training and testing ...
Lab 2: Classification and Regression Prediction Models, training and testing ...Lab 2: Classification and Regression Prediction Models, training and testing ...
Lab 2: Classification and Regression Prediction Models, training and testing ...
 
Python for data analysis
Python for data analysisPython for data analysis
Python for data analysis
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Python for Data Analysis.pdf
Python for Data Analysis.pdfPython for Data Analysis.pdf
Python for Data Analysis.pdf
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Azure machine learning service
Azure machine learning serviceAzure machine learning service
Azure machine learning service
 
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
 
Viktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning ServiceViktor Tsykunov: Azure Machine Learning Service
Viktor Tsykunov: Azure Machine Learning Service
 
K-Means Algorithm Implementation In python
K-Means Algorithm Implementation In pythonK-Means Algorithm Implementation In python
K-Means Algorithm Implementation In python
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdf
 
Ceilometer + Heat = Alarming
Ceilometer + Heat = Alarming Ceilometer + Heat = Alarming
Ceilometer + Heat = Alarming
 
Autoscaling in kubernetes v1
Autoscaling in kubernetes v1Autoscaling in kubernetes v1
Autoscaling in kubernetes v1
 
Introduction to Chainer 11 may,2018
Introduction to Chainer 11 may,2018Introduction to Chainer 11 may,2018
Introduction to Chainer 11 may,2018
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learning
 
I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)
 
Machine learning Experiments report
Machine learning Experiments report Machine learning Experiments report
Machine learning Experiments report
 
Xgboost
XgboostXgboost
Xgboost
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
 

Kürzlich hochgeladen

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 

Kürzlich hochgeladen (20)

Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 

Pyclustering tutorial - K-means

  • 1. PyClustering: K-Means Tutorial Pyclustering Library Tutorial Theme: K-Means Library Version: 0.8.1 Author: Andrei Novikov E-Mail: pyclustering@yandex.ru
  • 2. Agenda ● PyClustering K-Means Features; ● Input format for K-Means; ● Data clustering using K-Means; ● Additional parameters of the algorithm; ● Data clustering result visualization; ● Image segmentation by K-Meas;
  • 3. PyClustering K-Means Features ● Python implementation based on numpy. ● C/C++ implementation – core library that is supported for 32, 64-bit Windows, Linux. ● K-Means observer to collect information about clustering process on each iteration. ● K-Means visualizer to display and animate K-Means specific results. C/C++ implementation can be used without python if integration with C/C++ project is required. Use sources from „pyclustering/ccore“.
  • 4. Import K-Means K-Means algorithm and its features can be imported from „pyclustering.cluster.kmeans“: from pyclustering.cluster.kmeans import kmeans from pyclustering.cluster.kmeans import kmeans_observer from pyclustering.cluster.kmeans import kmeans_visualizer
  • 5. Input data format for K-Means K-Means algorithm uses array_like data format, for example, list where each element is point that is represented by coordinates. Here is an example of 1-D data: dataset = [ [0.25], [0.43], [1.34], [-0.56] ] Example of 2-D data: dataset = [ [0.1, 0.2], [0.1, 0.6], [0.2, -1.4] ] Example of 3-D data: dataset = [ [0.6, 0.1, 0.4], [0.2, 0.1, 0.9] ]
  • 6. Clustering by K-Means algorithm K-Means uses two general parameters for clustering: input data and initial cluster centers. from pyclustering.cluster.kmeans import kmeans from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer; from pyclustering.utils import read_sample; data = [ [0.1], [0.2], [0.5], [0.3], [1.5], [1.8], [1.3], [1.6], [1.5] ] initial_centers = kmeans_plusplus_initializer(data, 2).initialize() instance = kmeans(data, initial_centers) instance.process() # perform processing clusters = instance.get_clusters(); # allocated clusters centers = instance.get_centers(); # cluster centers
  • 7. Output result of K-Means K-Means algorithm returns allocated clusters and corresponding centers: ● Clusters are represented by list of clusters and each cluster contains object indexes from dataset, for example: [ [0, 1, 4], [2, 3, 5] ], where 0, 1, 4 – object indexes that forms the first cluster, and 2, 3, 5 – forms the second. ● Centers are represented by list of centers where each center is a point represented by coordinates.
  • 8. Library core usage By default core of pyclustering library that is called „ccore“ used for processing (C/C++ implementation of the algorithm). If platform is not supported then python implementation is used. There is special parameter that can be used to switch on/off core usage: # switch on core (switch on by default, and it is ignored if impossible to use core instance = kmeans(data, initial_centers, ccore=True) # switch off core (python implementation is used instead) instance = kmeans(data, initial_centers, ccore=False)
  • 9. K-Means result visualization Output result can be shown by common visualizer „cluster_visualizer“ from „pyclustering.cluster“ or by K- Means visualizer: instance = kmeans(sample, start_centers, 0.0001) instance.process() clusters = instance.get_clusters() centers = instance.get_centers() # visualize clustering results kmeans_visualizer.show_clusters(sample, clusters, centers, start_centers);
  • 10. Stop condition – tolerance K-Means calculates center changes on current and previous iterations and if difference is less than threshold value defined by parameter „tolerance“ than clustering process is over. Example with small data points: data = [ [0.0000001], [0.00000023], [0.00000051], [0.0000002] ] tolerance = 0.000000001 instance = kmeans(data, initial_centers, tolerance) But in case of very big or very small data values normalization should be used.
  • 11. K-Means visualizer Output result can be shown by common visualizer „cluster_visualizer“ from „pyclustering.cluster“ or by K- Means visualizer: instance = kmeans(sample, start_centers, 0.0001) instance.process() clusters = instance.get_clusters() centers = instance.get_centers() # visualize clustering results kmeans_visualizer.show_clusters(sample, clusters, centers, start_centers);
  • 12. Example of result visualization Here several examples of K-Means visualization:
  • 13. K-Means result animation K-Means clustering process can be visualized as an animation and saved to file. „kmeans_observer“ is used to collect information of each step of processing and the observer is used by „kmeans_visualizer“ then. observer = kmeans_visualizer() instance = kmeans(data, start_centers, observer=observer) instance.process() # animate clustering process kmeans_visualizer.animate_cluster_allocation(sample, observer); # or save animation to file kmeans_visualizer.animate_cluster_allocation(data, observer, save_movie=file.mp4);
  • 14. K-Means for segmentation K-Means can consider image as a data where each point represent pixel with three coordinate (RGB), or with four coordinate (RGBA). Here is an example of image segmentation using K-Means algorithm: from pyclustering.utils import draw_image_mask_segments, read_image from pyclustering.cluster.kmeans import kmeans; data = read_image(file_path_to_image); kmeans_instance = kmeans(data, start_centers); kmeans_instance.process(); clusters = kmeans_instance.get_clusters(); draw_image_mask_segments(source, clusters);
  • 15. Image segmentation results Here several examples of image segmentation by K- Means algorithm using pyclustering.
  • 16. References and Links ● Official pyclustering github repository: https://github.com/annoviko/pyclustering ● Official pypi pyclustering page: https://pypi.python.org/pypi/pyclustering/0.8.0 ● Official pyclustering web-site: https://pyclustering.github.io/
  • 17. Thank you for your attention Thank you!