<jupyter_start><jupyter_text>Unsuprevised Learning Clustering of imagesfor the project it is essential that we categorize images for this we first need to see if we can learn the pc which image belongs to which categorybefore we can do this there has to be defined what is a category and create a training set out of certain images.  Clustering methods in sklearn|Method name|Parameters|Scalability|Usecase|Geometry (metric used)||-----------|----------|-----------|-------|----------------------||K-Means|number of clusters|Very large n_samples, medium n_clusters withMiniBatch code|General-purpose, even cluster size, flat geometry, not too many clusters|Distances between points||Affinity propagation|damping, sample preference|Not scalable with n_samples|Many clusters, uneven cluster size, non-flat geometry|Graph distance (e.g. nearest-neighbor graph)||Mean-shift|bandwidth|Not scalable with n_samples|Many clusters, uneven cluster size, non-flat geometry|Distances between points||Spectral clustering|number of clusters|Medium n_samples, small n_clusters|Few clusters, even cluster size, non-flat geometry|Graph distance (e.g. nearest-neighbor graph)||Ward hierarchical clustering|number of clusters|Large n_samples and n_clusters|Many clusters, possibly connectivity constraints|Distances between points||Agglomerative clustering|number of clusters, linkage type, distance|Large n_samples and n_clusters|Many clusters, possibly connectivity constraints, non Euclidean distances|Any pairwise distance||DBSCAN|neighborhood size|Very large n_samples, medium n_clusters|Non-flat geometry, uneven cluster sizes|Distances between nearest points||Gaussian mixtures|many|Not scalable|Flat geometry, good for density estimation|Mahalanobis distances to centers||Birch|branching factor, threshold, optional global clusterer.|Large n_clusters and n_samples|Large dataset, outlier removal, data reduction.|Euclidean distance between points|Because of the data in the table above 5 types of clustering have been chosen to try out: - K-Means - Ward hierarchical clustering - Agglomerative clustering - DBSCAN - Birch<jupyter_code>from PIL import Image

#open image and convert to greyscale value
img = Image.open("../../downloader/pics/BaguEsbAgd7.jpg").convert('LA')

#convert greyscale image to numpy array
imgdata = np.asarray(img)
print(imgdata)<jupyter_output>[[[173 255]
  [173 255]
  [173 255]
  ...
  [ 21 255]
  [ 21 255]
  [ 22 255]]

 [[174 255]
  [174 255]
  [173 255]
  ...
  [ 20 255]
  [ 21 255]
  [ 22 255]]

 [[179 255]
  [178 255]
  [179 255]
  ...
  [ 19 255]
  [ 21 255]
  [ 23 255]]

 ...

 [[ 33 255]
  [ 33 255]
  [ 32 255]
  ...
  [ 14 255]
  [ 14 255]
  [ 14 255]]

 [[ 33 255]
  [ 33 255]
  [ 32 255]
  ...
  [ 14 255]
  [ 14 255]
  [ 14 255]]

 [[ 24 255]
  [ 32 255]
  [ 29 255]
  ...
  [ 15 255]
  [ 15 255]
  [ 15 255]]]<jupyter_text>K-Means<jupyter_code>from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
# test setup for k-means clustering
size= 40
points = 5 * np.random.rand(size,2)

#do clustering
kmeans = KMeans(n_clusters=5, random_state=0).fit(points)
centers = kmeans.cluster_centers_

#plot result with original data.
plt.scatter(points[:, 0], points[:, 1])
plt.scatter(centers[:, 0], centers[:, 1], s=10000, c="lightblue", cmap="Blues", alpha=0.5, edgecolors="grey", linewidth=2)
plt.show()<jupyter_output><empty_output><jupyter_text>Ward Hierarchical Clustering<jupyter_code>from sklearn.cluster import AgglomerativeClustering
from sklearn import manifold

points = 5 * np.random.rand(size,2)

clustering = AgglomerativeClustering(linkage='ward', n_clusters=10)
clustering.fit(points)

center = clustering.

plt.scatter(points[:, 0], points[:, 1])
plt.scatter(centers[:, 0], centers[:, 1], s=10000, c="lightblue", cmap="Blues", alpha=0.5, edgecolors="grey", linewidth=2)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12396480331262939, 'fraction_numerical': 0.05822981366459627, 'mean_word_length': 4.7859281437125745, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '315662', 'license': 'MIT', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1200, 'n_words': 387, 'path': 'machine learning/Unsuprevised (Images)/Demian.ipynb', 'repo_name': 'DemianMelskens/CBS', 'size': '3864'}