AdaBoost This blog post will provide you with a comprehensive overview of Adaboost, exploring the theory behind this probabilistic algorithm and demonstrating its implementation using Python libraries. Dive in to uncover the advantages and disadvantages of neural network, as well as its real-world applications across various domains. With that, enjoy your journey in QDO! What is Adaboost AdaBoost (Adaptive Boosting) is an ensemble learning technique that combines multiple weak classifiers (often decision trees) to create a strong classifier. It works by training the weak classifiers sequentially, giving more weight to misclassified instances at each step so that subsequent classifiers focus more on the harder cases. The final prediction is made by combining the weighted votes of all weak classifiers. AdaBoost is effective at reducing bias and variance, and it’s particularly good for binary classification problems. However, it can be sensitive to noisy data and outliers. Concepts o...
K-MEANS
This blog post will provide you with a comprehensive overview of K-means, exploring the theory behind this probabilistic algorithm and demonstrating its implementation using Python libraries. Dive in to uncover the advantages and disadvantages of K-means, as well as its real-world applications across various domains. With that, enjoy your journey in QDO!
WHAT IS K-MEANS
K-means is an unsupervised machine learning algorithm primarily used for clustering tasks. It aims to partition a dataset into a specified number of clusters , where each data point belongs to the cluster with the nearest mean, which serves as the "centroid" of that cluster. The algorithm starts by randomly initializing centroids, and each data point is assigned to the nearest centroid, forming temporary clusters. After all points are assigned, the centroids are recalculated as the mean of the points within each cluster. This process of assignment and centroid recalculation iterates until the centroids stabilize or until a set number of iterations is reached.
Concept of random forest
Lets say we want to cluster all the genes and we have all the data of the gene plotted on the line
We start by selecting 3 random data points as our initial cluster point
Next, we cluster the remaining data base on the distance to the cluster point
Next, we find the center point/mean for each cluster and the whole process repeats again
The number ok k-means can be best determine through the elbow method below in which we plot the number of clusters and reduction in variation for each of the clusters.
Implementation of k-means in python
Importing libraries
from sklearn.datasets import load_iris
Loading dataset
iris = load_iris()
Applying the model
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3, random_state=0)
Get prediction result
KModel = kmeans.fit(iris.data)
Get prediction accuracy
import pandas as pd
pd.crosstab(iris.target, KModel.labels_)
| col_0 | 0 | 1 | 2 |
|---|---|---|---|
| row_0 | |||
| 0 | 0 | 50 | 0 |
| 1 | 47 | 0 | 3 |
| 2 | 14 | 0 | 36 |
Parameters that you can tune in k-means
Number of Clusters (k):
- This is the number of groups you want to create. Choosing the right is important for meaningful clusters. Common methods to find the best include:
- Elbow Method: Plot the total distance between points and their cluster centers for different values of . The "elbow" point, where improvements slow down, suggests a good .
- Silhouette Score: A score that shows how distinct and well-separated your clusters are; higher scores are better.
Starting Points (Initialization Method):
- The algorithm starts by choosing initial "centroid" points. Choosing good starting points helps K-means find better clusters:
- Random: Picks starting points randomly, which can sometimes lead to poor results.
- k-means++: Selects starting points that are far apart, giving better results more consistently.
Maximum Iterations:
- This sets the maximum number of times K-means can adjust the clusters. This can be helpful if the algorithm is taking too long, allowing it to stop early after a set number of tries.
Convergence Tolerance:
- This controls when the algorithm should stop adjusting clusters. If the centroids barely move between adjustments, the algorithm will stop. Smaller values mean the algorithm will keep fine-tuning for longer, which can improve results but also takes more time.
Number of Runs (n_init):
- K-means can be run multiple times with different starting points to find the best grouping. The final result is chosen as the one with the lowest total distance between points and their cluster centers. More runs can improve results, but also take longer.
Algorithm Variant:
- Different versions of K-means handle data slightly differently to improve speed:
- Standard K-means: The most common and straightforward method.
- Optimized K-means (like Elkan’s): Uses shortcuts to speed things up, especially helpful with large, high-dimensional data.
Advantages and disadvantages of k-means
Advantages
Simple and Fast:
- K-means is easy to understand and implement. It’s also computationally efficient, especially on large datasets, making it suitable for real-time applications.
Works Well with Convex Clusters:
- K-means is effective when clusters are spherical and of similar size, often producing clear, well-separated clusters under these conditions.
Scalable:
- K-means can handle large datasets and can be scaled with parallel or mini-batch versions, making it useful for big data.
Disadvantages
Sensitive to Initial Choices:
- The initial placement of centroids can significantly affect the final clusters, sometimes leading to suboptimal results. Different initializations can produce different outcomes.
Requires Specification of :
- You need to specify the number of clusters () in advance, which isn’t always straightforward and can lead to trial and error or require additional methods to estimate the best .
Assumes Spherical Clusters:
- K-means assumes clusters are roughly circular and evenly sized, so it struggles with complex shapes or clusters of very different sizes, leading to poor performance in these cases.




Comments
Post a Comment