Answers.Body: <p>A typical clustering algorithm is k-means (and <a href="https://stats.stackexchange.com/q/56500/82135">not k-NN, i.e. k-nearest neighbours, which is primarily used for classification</a>). There are other clustering algorithms, such as <a href="https://en.wikipedia.org/wiki/Hierarchical_clustering" rel="nofollow noreferrer">hierarchical clustering algorithms</a>. <code>sklearn</code> provides functions that implement <a href="https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html" rel="nofollow noreferrer">k-means</a> (and <a href="https://scikit-learn.org/stable/auto_examples/cluster/plot_cluster_iris.html#sphx-glr-auto-examples-cluster-plot-cluster-iris-py" rel="nofollow noreferrer">an example</a>), <a href="https://scikit-learn.org/stable/modules/clustering.html#hierarchical-clustering" rel="nofollow noreferrer">hierarchical clustering algorithms</a>, and <a href="https://scikit-learn.org/stable/modules/clustering.html" rel="nofollow noreferrer">other clustering algorithms</a>.</p>
  
  <p>To assess the quality of the produced clusters, you could use the <a href="https://en.wikipedia.org/wiki/Silhouette_(clustering)" rel="nofollow noreferrer">silhouette method</a> (<code>sklearn</code> provides a function that can be used to compute the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.silhouette_score.html" rel="nofollow noreferrer">silhouette score</a>).</p>
  
  <p>Regarding your specific data frame, note that it contains repetitions, so you may want to remove them before starting the clustering procedure. Also, the IDs are not unique, but you probably don't need the IDs for clustering.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-13T10:44:54.773Z
Answers.Text: how can I cluster this.give me the code for my data frame please
Answers.UserDisplayName: tosiful islam
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-13T12:07:20.023Z
Answers.Text: @t This site is not appropriate for providing code. We are not here to solve your issues, but to help you. Also, note that we are volunteers. Anyway, maybe later I will provide some code to illustrate how you could do that. Meanwhile, I provided many links to useful articles that should help you.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-13T18:52:49.533Z
Answers.Text: Ok, no problem. I am a beginner that's why I face the problem.I will follow your link
Answers.UserDisplayName: tosiful islam
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-12T16:50:09.697Z
Answers.LastActivityDate: 2020-04-12T16:50:09.697Z
Answers.UserDisplayName: nbro
Answers.Body: <p>Yes you can use KNN algorithm to cluster (well actually its a classification not a clustering if you use KNN) the data. <strong>But,</strong> first you need to set one feature as a label because KNN is a supervised learning method, it need a labeled data to train the data first. For example you can use Gender as label to classify the data. To determine the quality of the classification result, you can simply use accuracy.</p>
  
  <p>If you don’t want to use a label, you can use unsupervised learning method like K-Means to do the clusters. Because its unsupervised it doesn’t need label so you can use all of the feature to do the clusters task. For the k-means algorithm you can use a library from scikit-learn or create it from scratch. To evaluate the results you can use silhouette score or elbow method (to find the optimal number of cluster).</p>
  
  <p>And don’t forget to do data exploration because maybe it can increase the quality of the cluster results.</p>
  
  <p>You can learn more about the differentiation between K-Means and KNN in the link below:
  <a href="https://pythonprogramminglanguage.com/how-is-the-k-nearest-neighbor-algorithm-different-from-k-means-clustering/" rel="nofollow noreferrer">https://pythonprogramminglanguage.com/how-is-the-k-nearest-neighbor-algorithm-different-from-k-means-clustering/</a></p>
  
  <p>I hope this helps :)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-21T10:21:31.500Z
Answers.LastActivityDate: 2020-04-21T11:09:58.563Z
Answers.LastEditDate: 2020-04-21T11:09:58.563Z
Answers.UserDisplayName: Shindy Trimaria Laxmi
Answers.Body: <p>KNN can be used in clustering with the data frame. but there are a number of steps that you must take.
  1. You must separate the features you want to cluster. for example you can do clustering dob and age.
  2. if there is data of type string you have to change it to an integer.
  For easier clustering, you can use the Sklearn library. you can access at the following link <a href="https://scikit-learn.org/stable/modules/clustering.html" rel="nofollow noreferrer">https://scikit-learn.org/stable/modules/clustering.html</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-21T09:26:15.560Z
Answers.LastActivityDate: 2020-04-21T09:26:15.560Z
Answers.UserDisplayName: bayu pramana
Answers.Body: <p>you can clustering the data frame with unsupervised algorithm, for example you can use K-Means method. There are some options you can choose to eliminate some features in your data frame, like del dataFrame['Column Name']. In unsupervised learning, the algorithm not calculate the quality of the clusters, but you can set it up by yourself to make a parameter for calculate the quality for each clusters, for example it depend on sum of data in each clusters. Actually you can use KNN algorithm with your data frame, but you need to add a label in there because KNN is a supervised learning, and its function to make a classification, not clustering. hope it useful.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-21T10:55:37.910Z
Answers.LastActivityDate: 2020-04-21T10:55:37.910Z
Answers.UserDisplayName: Kartiko Nurhada' W.
Answers.Body: <p>You can use k-nn clustering but you must convert your dataset to numeric values or you can remove the unrelated features in your dataset. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-21T09:22:31.630Z
Answers.LastActivityDate: 2020-04-21T15:26:52.323Z
Answers.LastEditDate: 2020-04-21T15:26:52.323Z
Answers.UserDisplayName: MUHAMMAD BAYU FIRDAUS
Answers.Body: <p>There are several algorithm for clustering such as: K-means, Mean shift, hierarchical,etc. Based on my experience, actually it's K-means(KNN for classifcication).It is suitable for clustering your dataset, there are several steps for clustering your dataset:</p>
  
  <ol>
  <li>You have to determine which features that you want cluster</li>
  <li>Changing your categorical dataset to numerical </li>
  <li>This step is optional, You can drop columns that are not related to the features you have chosen before</li>
  <li>Try to to code your clustering (like determine centroid from your dataset, calculate the euclidean distance from your centroid,etc) or if you want to use library maybe sklearn is the right place.</li>
  </ol>
  
  <p>And for determine the quality of your clustering, you can measures SSE(sum of the square error from the items of each cluster),Inter cluster distance,Intra cluster distance for each cluster,Maximum Radius,Average Radius.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-21T10:12:53.027Z
Answers.LastActivityDate: 2020-04-21T10:26:38.757Z
Answers.LastEditDate: 2020-04-21T10:26:38.757Z
Answers.UserDisplayName: Muhammad Fadhil Ihsan
Body: <p>How can I cluster the data frame below with several features and observations? And how would I go about determining the quality of those clusters? Is k-NN appropriate for this?</p>
  
  <pre><code>id     Name             Gender   Dob    Age  Address
  1   MUHAMMAD JALIL      Male    1987    33   Chittagong
  1   MUHAMMAD JALIL      Male    1987    33   Chittagong
  2   MUHAMMAD JALIL      Female  1996    24   Rangpur
  2   MRS. JEBA           Female  1996    24   Rangpur
  3   MR. A. JALIL        Male    1987    33   Sirajganj
  3   MR. A. JALIL        Male    1987    33   Sirajganj
  3   MD. A. JALIL        Male    1987    33   Sirajganj
  4   MISS. JEBA          Female  1996    24   Rangpur
  4   PROF. JEBA          Female  1996    24   Rangpur
  1   MD. A. JALIL        Male    1987    33   Chittagong
  1   MUHAMMAD A. JALIL   Male    1987    33   Chittagong
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-12T15:53:38.120Z
Comments.Text: If you are looking for code, your question is off-topic here. Are you looking for code or for some guidance on how to do it?
Comments.UserDisplayName: nbro
Tags: <python><datasets><unsupervised-learning><clustering>
Title: How can I cluster this data frame with several features and observations?
UserDisplayName: tosiful islam
ThreadText: # How can I cluster this data frame with several features and observations?
  
  (Asked by: username_0 on 2020-04-12)
  
  How can I cluster the data frame below with several features and observations? And how would I go about determining the quality of those clusters? Is k-NN appropriate for this?
  
  ```
  id     Name             Gender   Dob    Age  Address
  1   username_5 JALIL      Male    1987    33   Chittagong
  1   username_5 JALIL      Male    1987    33   Chittagong
  2   username_5 JALIL      Female  1996    24   Rangpur
  2   MRS. JEBA           Female  1996    24   Rangpur
  3   MR. A. JALIL        Male    1987    33   Sirajganj
  3   MR. A. JALIL        Male    1987    33   Sirajganj
  3   MD. A. JALIL        Male    1987    33   Sirajganj
  4   MISS. JEBA          Female  1996    24   Rangpur
  4   PROF. JEBA          Female  1996    24   Rangpur
  1   MD. A. JALIL        Male    1987    33   Chittagong
  1   username_5 A. JALIL   Male    1987    33   Chittagong
  
  ```
  
  **Tags:** python, datasets, unsupervised-learning, clustering
  
  > **Comments:**
  > **username_1**: If you are looking for code, your question is off-topic here. Are you looking for code or for some guidance on how to do it?  
  
  ---
  
  ## 6 answers
  
  ### Answer by username_1 on 2020-04-12. Score: 2
  
  A typical clustering algorithm is k-means (and [not k-NN, i.e. k-nearest neighbours, which is primarily used for classification](https://stats.stackexchange.com/q/56500/82135)). There are other clustering algorithms, such as [hierarchical clustering algorithms](https://en.wikipedia.org/wiki/Hierarchical_clustering). `sklearn` provides functions that implement [k-means](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html) (and [an example](https://scikit-learn.org/stable/auto_examples/cluster/plot_cluster_iris.html#sphx-glr-auto-examples-cluster-plot-cluster-iris-py)), [hierarchical clustering algorithms](https://scikit-learn.org/stable/modules/clustering.html#hierarchical-clustering), and [other clustering algorithms](https://scikit-learn.org/stable/modules/clustering.html).
  
  To assess the quality of the produced clusters, you could use the [silhouette method](https://en.wikipedia.org/wiki/Silhouette_(clustering)) (`sklearn` provides a function that can be used to compute the [silhouette score](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.silhouette_score.html)).
  
  Regarding your specific data frame, note that it contains repetitions, so you may want to remove them before starting the clustering procedure. Also, the IDs are not unique, but you probably don't need the IDs for clustering.
  
  > **Comments:**
  > **username_0**: how can I cluster this.give me the code for my data frame please  
  > **username_1**: @t This site is not appropriate for providing code. We are not here to solve your issues, but to help you. Also, note that we are volunteers. Anyway, maybe later I will provide some code to illustrate how you could do that. Meanwhile, I provided many links to useful articles that should help you.  
  > **username_0**: Ok, no problem. I am a beginner that's why I face the problem.I will follow your link  
  
  ---
  
  ### Answer by username_2 on 2020-04-21. Score: 1
  
  Yes you can use KNN algorithm to cluster (well actually its a classification not a clustering if you use KNN) the data. **But,** first you need to set one feature as a label because KNN is a supervised learning method, it need a labeled data to train the data first. For example you can use Gender as label to classify the data. To determine the quality of the classification result, you can simply use accuracy.
  
  If you don’t want to use a label, you can use unsupervised learning method like K-Means to do the clusters. Because its unsupervised it doesn’t need label so you can use all of the feature to do the clusters task. For the k-means algorithm you can use a library from scikit-learn or create it from scratch. To evaluate the results you can use silhouette score or elbow method (to find the optimal number of cluster).
  
  And don’t forget to do data exploration because maybe it can increase the quality of the cluster results.
  
  You can learn more about the differentiation between K-Means and KNN in the link below:
  <https://pythonprogramminglanguage.com/how-is-the-k-nearest-neighbor-algorithm-different-from-k-means-clustering/>
  
  I hope this helps :)
  
  
  ---
  
  ### Answer by username_3 on 2020-04-21. Score: 0
  
  KNN can be used in clustering with the data frame. but there are a number of steps that you must take.
  1. You must separate the features you want to cluster. for example you can do clustering dob and age.
  2. if there is data of type string you have to change it to an integer.
  For easier clustering, you can use the Sklearn library. you can access at the following link <https://scikit-learn.org/stable/modules/clustering.html>
  
  
  ---
  
  ### Answer by username_4 on 2020-04-21. Score: 0
  
  you can clustering the data frame with unsupervised algorithm, for example you can use K-Means method. There are some options you can choose to eliminate some features in your data frame, like del dataFrame['Column Name']. In unsupervised learning, the algorithm not calculate the quality of the clusters, but you can set it up by yourself to make a parameter for calculate the quality for each clusters, for example it depend on sum of data in each clusters. Actually you can use KNN algorithm with your data frame, but you need to add a label in there because KNN is a supervised learning, and its function to make a classification, not clustering. hope it useful.
  
  
  ---
  
  ### Answer by username_5 on 2020-04-21. Score: 0
  
  You can use k-nn clustering but you must convert your dataset to numeric values or you can remove the unrelated features in your dataset.
  
  
  ---
  
  ### Answer by username_6 on 2020-04-21. Score: 0
  
  There are several algorithm for clustering such as: K-means, Mean shift, hierarchical,etc. Based on my experience, actually it's K-means(KNN for classifcication).It is suitable for clustering your dataset, there are several steps for clustering your dataset:
  
  1. You have to determine which features that you want cluster
  2. Changing your categorical dataset to numerical
  3. This step is optional, You can drop columns that are not related to the features you have chosen before
  4. Try to to code your clustering (like determine centroid from your dataset, calculate the euclidean distance from your centroid,etc) or if you want to use library maybe sklearn is the right place.
  
  And for determine the quality of your clustering, you can measures SSE(sum of the square error from the items of each cluster),Inter cluster distance,Intra cluster distance for each cluster,Maximum Radius,Average Radius.
  
  
  ---
  
  