title: Evaluating K-means accuracy
body: <p>I created a 3-dimensional random data sets with 4 defined patterns/classes in MATLAB.  I applied the K-means algorithm on the data to see how well K-means can classify my samples based on created 4 patterns/classes.</p>
  
  <p>I need help with the following; </p>
  
  <ol>
  <li>What function/code can I use to evaluate how well the K-means algorithm has identified the classes of my samples correctly? Assuming I set K=4 as illustrated in the image below:</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/TmM9p.png" alt="enter image description here"></p>
  
  <ol start="2">
  <li>How can I automatically identify the number of classes (K)? Assuming the classes in my data is unknown? </li>
  </ol>
  
  <hr>
  
  <p>My aim is to evaluate K-mean's accuracy and how changes to the data (by pre-processing) affects the algorithm’s ability to identify classes. Examples with MATLAB code would be helpful!</p>