0% found this document useful (0 votes)
9 views

ML Notes 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

ML Notes 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Unsupervised Learning

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:

1. Choose the number of clusters ( K ).

2. Initialize the centroids randomly.

3. Assign each data point to the nearest centroid.

4. Recalculate the centroids as the mean of all points in the cluster.

5. Repeat steps 3 and 4 until convergence (i.e., when the assignments no longer change).

- Python Example:

```python

from sklearn.cluster import KMeans

import numpy as np

# Sample data

X = np.array([[1, 2], [1, 4], [1, 0],

[10, 2], [10, 4], [10, 0]])

# KMeans model

kmeans = KMeans(n_clusters=2, random_state=0).fit(X)

# Cluster centers and labels

print(kmeans.cluster_centers_)

print(kmeans.labels_)
```

2. DBSCAN (Density-Based Spatial Clustering of Applications with Noise):


- Definition: A density-based clustering algorithm that groups together points that are closely packed together,
marking points that are far away as outliers.

- Algorithm Steps:

1. Choose parameters \( \epsilon \) (radius) and \( \text{minPts} \) (minimum number of points required to form a
dense region).

2. For each point, retrieve all points within \( \epsilon \).

3. If the number of points is greater than or equal to \( \text{minPts} \), a cluster is formed.

4. Expand the cluster by recursively including all density-reachable points.

5. Mark any points not belonging to any cluster as noise.

- Python Example:

```python

from sklearn.cluster import DBSCAN

import numpy as np

# Sample data

X = np.array([[1, 2], [2, 2], [2, 3],

[8, 7], [8, 8], [25, 80]])

# DBSCAN model

db = DBSCAN(eps=3, min_samples=2).fit(X)

# Core samples, labels

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:

1. Naive Bayes Classifier:


- Definition: A probabilistic classifier based on Bayes' Theorem, assuming that the features are independent given the
class label.

- Algorithm Steps:

1. Calculate the prior probability for each class.

2. Calculate the likelihood of each feature given each class.

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

from sklearn.naive_bayes import GaussianNB

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])

# Naive Bayes model

model = GaussianNB()

model.fit(X, y)

# Predicting new data

print(model.predict([[3, 5]]))

```

You might also like