you can try below approach
centroids is a matrix with all cluster centers
TestData_vector=[130,170,250,300] #you new test data as a vector
import numpy as np
from sklearn.metrics.pairwise import euclidean_distances
1.you just have to represent those features as numeric in a vector
2.Its a good practise to normalize vector i just took sum of elements and divide by each element by that sum of elements =[0.06666666666666667,0.13333333333333333,0.2,0.26666666666666666,0.3333333333333333]
normalize the values in that vector to be between 0 -1
3.feed the ...
Sklearn provides a predict function for the KMeans object. So something like this should work:
model = KMeans(clusters=2, random_state=42)
# get centroids
centroids = model.cluster_centers_
test_data_point = pass
KMeans assigns data points to clusters is by calculating the Euclidean distance between ...
I would use all the features and see how the separateness of my clusters behave according to some metric, for example, silhouette score
Additionally, it is very important to scale your data prior to clustering since kmeans is a distance-based algorithm.
heart_data = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/00519/...
Yes it can happen. In fact it is quite normal since there are different clusters in 2D and different in 3D, since more or less information is added to data (by having more dimensions). This is a by-product of the curse of dimensionality.
Adding as more relevant information as possible would make clusters more close to underlying groups. So 3D would be better ...
In general, even using k-means more than once will create slightly different clusters (that s if you do not set a random seed).
Ideally, the profiles of the clusters and the distribution of data points into them will be the similar. If this is the case then it shouldn't really matter which one you choose. If not then, I suggest you examine carefully what ...
This is a known problem of automatic clustering, how to choose / adapt the number of clusters so it represents the "real" clusters.
Hierarchical clustering is more helpful in this regard. For algorithms like K-means this is not so easy and research has tried various approaches to determine the optimum number of clusters (eg employing Information-...
Is it necessary to plot all points? If not, you can use plot3d to display 6 bubbles centered at each clusters center. You can use mean within distance for each cluster to set the radius of each cluster (you will have to normalize this) and a color range to display the number of points in each cluster.
Your case is where K=number of points in dataset :
K-means: Lets suppose, there are 10 data points and k=10, so you have 10 clusters. the new test point will be matched with the cluster nearest to it
KNN: If K=1, then the new test point classified will be same as in K-means.
So, if there is one data-point per cluster, then your given answer ie. knn is ...