ML Notes 1
ML Notes 1
Definition:
Unsupervised learning is a type of machine learning where the model is trained on unlabeled data, meaning the data
does not have predefined categories or labels. The goal is to infer the natural structure present within a set of data
points.
Common Algorithms:
1. K-Means Clustering:
- Definition: A partitioning method which divides the data into K clusters, where each data point belongs to the cluster
with the nearest mean.
- Algorithm Steps:
5. Repeat steps 3 and 4 until convergence (i.e., when the assignments no longer change).
- Python Example:
```python
import numpy as np
# Sample data
# KMeans model
print(kmeans.cluster_centers_)
print(kmeans.labels_)
```
- Algorithm Steps:
1. Choose parameters \( \epsilon \) (radius) and \( \text{minPts} \) (minimum number of points required to form a
dense region).
3. If the number of points is greater than or equal to \( \text{minPts} \), a cluster is formed.
- Python Example:
```python
import numpy as np
# Sample data
# DBSCAN model
db = DBSCAN(eps=3, min_samples=2).fit(X)
print(db.core_sample_indices_)
print(db.labels_)
```
Supervised Learning
Definition:
Supervised learning is a type of machine learning where the model is trained on labeled data, meaning the data has
predefined categories or labels. The goal is to learn a mapping from inputs to outputs.
Common Algorithm:
- Algorithm Steps:
3. Use Bayes' Theorem to calculate the posterior probability for each class given a new data point.
4. Assign the class with the highest posterior probability to the data point.
- Python Example:
```python
import numpy as np
# Sample data
X = np.array([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]])
y = np.array([0, 0, 1, 1, 1])
model = GaussianNB()
model.fit(X, y)
print(model.predict([[3, 5]]))
```