Write a program using K-Means and Expectation Maximization clustering for the gi
ID: 3804221 • Letter: W
Question
Write a program using K-Means and Expectation Maximization clustering for the given dataset. You have been assigned a dataset.
How to use this dataset in R:
Package Name: cluster.datasets
install.packages("cluster.datasets")
library(cluster.datasets)
data(paste your data set name)
your dataset name
data(mammal.dentition)
Program 1: K-Means Clustering
Q1: Find optimal number of clusters. (Hint: Elbow Method)
Q2: Apply K-Means
Q3: Visualization for K-Means Clustering
Program 2: Expectation Maximization Clustering
Q1: Apply Expectation Maximization
Q2: Visualization for Expectation Maximization
Write a program using K-Means and Expectation Maximization clustering for the given dataset. You have been assigned a dataset.
How to use this dataset in R:
Package Name: cluster.datasets
install.packages("cluster.datasets")
library(cluster.datasets)
data(paste your data set name)
your dataset name
data(mammal.dentition)
Program 1: K-Means Clustering
Q1: Find optimal number of clusters. (Hint: Elbow Method)
Q2: Apply K-Means
Q3: Visualization for K-Means Clustering
Program 2: Expectation Maximization Clustering
Q1: Apply Expectation Maximization
Q2: Visualization for Expectation Maximization
Explanation / Answer
import java.util.ArrayList;
import java.util.List;
public category Cluster purpose centroid;
public int id;
//Creates a brand new Cluster
public Cluster(int id)
public List getPoints() come points;
}
public void addPoint(Point point)
public void setPoints(List points)
public purpose getCentroid() come centroid;
}
public void setCentroid(Point centroid) center of mass;
}
public int getId()
public void clear()
public void plotCluster()
System.out.println("]");
}
}
Point.java
package com.dataonfocus.clustering;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public category purpose personal double x = 0;
non-public double y = 0;
non-public int cluster_number = 0;
public Point(double x, double y)
public void setX(double x)
public double getX() come back this.x;
}
public void setY(double y)
public double getY() come back this.y;
}
public void setCluster(int n)
public int getCluster() come back this.cluster_number;
}
//Calculates the space between 2 points.
protected static double distance(Point p, purpose centroid) come back science.sqrt(Math.pow((centroid.getY() - p.getY()), 2) + Math.pow((centroid.getX() - p.getX()), 2));
}
//Creates random purpose
protected static purpose createRandomPoint(int min, int max) come back new Point(x,y);
}
protected static List createRandomPoints(int min, int max, int number)
come points;
}
public String toString() come "("+x+","+y+")";
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.dataonfocus.clustering;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public category purpose {
non-public double x = 0;
non-public double y = 0;
non-public int cluster_number = 0;
public Point(double x, double y)
public void setX(double x)
public double getX() come back this.x;
}
public void setY(double y)
public double getY() come back this.y;
}
public void setCluster(int n)
public int getCluster() come back this.cluster_number;
}
//Calculates the space between 2 points.
protected static double distance(Point p, purpose centroid) come back science.sqrt(Math.pow((centroid.getY() - p.getY()), 2) + Math.pow((centroid.getX() - p.getX()), 2));
}
//Creates random purpose
protected static purpose createRandomPoint(int min, int max) come back new Point(x,y);
}
protected static List createRandomPoints(int min, int max, int number)
come points;
}
public String toString() come "("+x+","+y+")";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.