in Education by
Can I specify my own distance function using scikit-learn K-Means Clustering? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
@Rony, Yes, it is possible to specify your own distance function. K-means clustering is one of the most widely used unsupervised machine learning algorithms which generates clusters of data based on the similarity between various data instances. K-means algorithm starts by randomly choosing a centroid value for each cluster. After that the algorithm iteratively performs three steps: 1. Find the Euclidean distance between each data instance and centroids of all the clusters 2. Assign the data instances to the cluster of the centroid with the nearest distance 3. Calculate new centroid values based on the mean values of the coordinates of all the data instances from the corresponding cluster. Use this example to understand how to specify your own distance function- from pyclustering.cluster.kmeans import kmeans from pyclustering.utils.metric import type_metric, distance_metric myfunc = lambda point1, point2: point1[0] + point2[0] + 2 metric = distance_metric(type_metric.USER_DEFINED, func=myfunc) scenters = [[2.9, 3.4], [5.9, 6.7]]; kinstance = kmeans(sample, start_centers, metric=metric) kinstance.process() clstr = kinstance.get_clusters()

Related questions

0 votes
    Today I'm trying to learn something about K-means. I Have understood the algorithm and I know how it works. Now I ... a lot of time? Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    The classifiers in machine learning packages like liblinear and nltk offer a method show_most_informative_features(), which ... lot! Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    How can I extract the decision path as a textual list from a trained tree in a decision tree ? Something similar to ... then class='A' Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How can I save a trained Naive Bayes classifier to a disk and use it for predicting data? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    There is only one question related to this and it is more about which one is better. I just don't ... exactly lies the difference? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why scikit learn is used? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is test size in Scikit learn? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what should I learn Scikit learn or TensorFlow? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    While training a tensorflow seq2seq model I see the following messages : W tensorflow/core/common_runtime/gpu/pool_allocator ... GB GPU Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    While training a tensorflow seq2seq model I see the following messages : W tensorflow/core/common_runtime/gpu/pool_allocator ... GB GPU Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Classification problems, such as logistic regression or multinomial logistic regression, optimize a cross-entropy loss. ... jungle. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I am trying to groupby a column and compute value counts on another column. import pandas as pd dftest = pd. ... Amt, already exists Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have just built my first model using Keras and this is the output. It looks like the standard output you get ... - loss: 0.1928 Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I can't decipher however the sklearn.pipeline.Pipeline works precisely. Some explanation in this documentation. What ... estimator)]) Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
...