Download Data Clustering: DBSCAN, K-Means, Agglomerative, and Gaussian Mixture and more Assignments Artificial Intelligence in PDF only on Docsity!
ARTIFICIAL INTELLIGENCE
Lab task
Questions:
A) IDENTIFY AND BRIEFLY EXPLAIN LIST OF CLUSTERING ALGORITHMS USED IN ARTIFICIAL
INTELLIGENCE. (ATLEAST 5 ALGORITHMS)
1. DBSCAN ALGORITHM: (Density-Based):
DBSCAN:
DBSCAN short for Density-Based Spatial Clustering of Applications with Noise. It is an unsupervised machine learning method. It is used to design models. It is used for data clustering and data mining. As a data clustering mechanism, it is used to separate high and low-density clusters. It is also a connectivity-based algorithm where based on connected points, dense regions are found. Some points related to DBSCAN: For cluster formation, it groups together those points which are near to each other. To calculate the distance between points Euclidean distance is used commonly. Also, each cluster is supposed to contain 'n' points, where 'n' represents the minimum number of points present in a cluster. If the cluster has points less than 'n', it shows the low-density region. Two important parameters of DBSCAN:
- epsilon: It is a radius within which a number of connected points are found.
- minimum points: It is the number of points that should be available in a region to make a cluster. Important Terms used in DBSCAN: Core point: An internal point of the cluster which has minimum points in its proximity. Border point: It is available in the neighborhood of the core point but doesn't have minimum points in its proximity. Noise point: It is neither a core point nor a border point. Example: Let's say 'a' is a given point, and specified epsilon value is 'x' and density is 4. Since 'a' has 6 points in the cluster including itself which is more than 4, 'a' is a core point. 'b' doesn't have points equal to or more than 4, but it is also in the neighborhood of 'a', hence 'b' is the border point. 'c' is the noise point as it is neither the core nor the border point.
Agglomerative clustering is best at finding small clusters. The end result looks like a
dendrogram so that you can easily visualize the clusters when the algorithm finishes.
4. Gaussian Mixture Model algorithm
A Gaussian mixture model is a probabilistic model that assumes all the data points are
generated from a mixture of a finite number of Gaussian distributions with unknown
parameters
One of the problems with k-means is that the data needs to follow a circular format. The way k-
means calculates the distance between data points has to do with a circular path, so non-
circular data isn't clustered correctly.
This is an issue that Gaussian mixture models fix. You don’t need circular shaped data for it to
work well.
The Gaussian mixture model uses multiple Gaussian distributions to fit arbitrarily shaped data.
There are several single Gaussian models that act as hidden layers in this hybrid model. So the
model calculates the probability that a data point belongs to a specific Gaussian distribution
and that's the cluster it will fall under.
5. Fuzzy c-means Algorithm:
Fuzzy c-means (FCM) is a data clustering technique in which a data set is grouped
into N clusters with every data point in the dataset belonging to every cluster to a certain
degree. For example, a data point that lies close to the center of a cluster will have a high
degree of membership in that cluster, and another data point that lies far away from the center
of a cluster will have a low degree of membership to that cluster.
The fcm function performs FCM clustering. It starts with a random initial guess for the cluster
centers; that is the mean location of each cluster. Next, fcm assigns every data point a random
membership grade for each cluster. By iteratively updating the cluster centers and the
membership grades for each data point, fcm moves the cluster centers to the correct location
within a data set and, for each data point, finds the degree of membership in each cluster. This
iteration minimizes an objective function that represents the distance from any given data
point to a cluster center weighted by the membership of that data point in the cluster.
B) FOR ABOVE IDENTIFIED ALGORITHMS, LIST DOWN THE APPLICATIONS FOR EACH 5
ALGORITHM SEPARATELY.
ANSWER:
1. DBSCAN:
Application:
- Scientific literature
- Images of Satellite
- Crystallography of X-ray
- Anomaly Detection in Temperature data
2. K-means:
Application:
- Academic performance
- Diagnostic systems
- Search engines
- Wireless sensor networks
- market segmentation
- document clustering
- image segmentation
- image compression
3. Agglomerative clustering algorithm
Application:
- Planar Range
- Image Segmentation
- Group objects in clusters based on their similarity.
- Quadric Range Image Segmentation.
4. Gaussian mixture models:
Application:
- extensively utilized in mining data
- recognition of pattern
- machine learning
- statistical analysis
- parameters are detected using maximal likelihood and EM algorithm and are modeled as latent variable.
5. Fuzzy C Means Algorithm
Applications:
- Used widely in Image Segmentation of medical imagery, especially the images generated by an
- MRI.
- Market definition
- segmentation
E) IMPLEMENT K-MEANS ALGORITHM IN PYTHON.
Answer:
-- coding: utf-8 --
""" Created on Wed Jun 22 08:52:42 2022 @author: amara """ import math from random import shuffle, uniform ###Auxiliary Function### def FindColMinMax(items): n = len(items[0]) minima = [float('inf') for i in range(n)] maxima = [float('-inf') for i in range(n)] for item in items: for f in range(len(item)): if(item[f] < minima[f]): minima[f] = item[f] if(item[f] > maxima[f]): maxima[f] = item[f] return minima,maxima
def EuclideanDistance(x,y): S = 0 #The sum of the squared differences of the elements for i in range(len(x)): S += math.pow(x[i]-y[i],2) return math.sqrt(S) #The square root of the sum def ManhattanDistance(x,y): S = 0 for i in range(len(x)): S += abs(x[i]-y[i]) return S def InitializeMeans(items,k,cMin,cMax): #Initialize means to random numbers between #the min and max of each column/feature f = len(items[0]) #number of features means = [[0 for i in range(f)] for j in range(k)] for mean in means: for i in range(len(mean)): #Set value to a random float #(adding +-1 to avoid a wide placement of a mean) mean[i] = uniform(cMin[i]+1,cMax[i]-1) return means def UpdateMean(n,mean,item): for i in range(len(mean)): m = mean[i]
index = i return index def CalculateMeans(k,items,maxIterations=100000): #Find the minima and maxima for columns cMin, cMax = FindColMinMax(items) #Initialize means at random points means = InitializeMeans(items,k,cMin,cMax) #Initialize clusters, the array to hold #the number of items in a class clusterSizes = [0 for i in range(len(means))] #An array to hold the cluster an item is in belongsTo = [0 for i in range(len(items))] #Calculate means for e in range(maxIterations): #If no change of cluster occurs, halt noChange = True for i in range(len(items)): item = items[i] #Classify item into a cluster and update the #corresponding means. index = Classify(means,item,selection) clusterSizes[index] += 1 means[index] = UpdateMean(clusterSizes[index],means[index],item) #Item changed cluster if(index != belongsTo[i]): noChange = False
belongsTo[i] = index #Nothing changed, return if(noChange): break return means if name == "main":
Input data
items = [[3,4],[3,6],[3,8],[4,5],[4,7],[5,1],[5,5],[7,3],[7,5],[8,5]] k = 3 print("Enetr 1 for euclidean distance and 2 for manhattam distance") selection = int(input()) means = CalculateMeans(k,items,selection) clusters = FindClusters(means,items) print("fianl centroids of 3 clusters is : ",means) print("Cluster 1 has ", clusters[0]) print("Cluster 2 has ", clusters[1]) print("Cluster 3 has ", clusters[2])