Unsupervised Learning

Python में Unsupervised Learning

Benjamin Wilson

Director of Research at lateral.io

Unsupervised learning

  • Unsupervised learning डेटा में पैटर्न ढूँढ़ता है
  • जैसे, ग्राहकों को उनकी खरीद पर clustering करना
  • खरीद पैटर्न से डेटा को compress करना (dimension reduction)
Python में Unsupervised Learning

Supervised बनाम unsupervised learning

  • Supervised learning भविष्यवाणी टास्क के लिए पैटर्न ढूँढ़ता है
  • जैसे, ट्यूमर को benign या cancerous के रूप में classify करना (labels)
  • Unsupervised learning डेटा में पैटर्न ढूँढ़ता है
  • ... लेकिन किसी खास prediction टास्क के बिना
Python में Unsupervised Learning

Iris डेटासेट

  • कई iris पौधों के माप
  • Iris की तीन species:
    • setosa
    • versicolor
    • virginica
  • Petal length, petal width, sepal length, sepal width (डेटासेट के features)

Iris

1 https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html
Python में Unsupervised Learning

Arrays, features और samples

  • 2D NumPy array
  • कॉलम माप हैं (features)
  • रो iris पौधों को दर्शाती हैं (samples)
Python में Unsupervised Learning

Iris डेटा 4-डायमेंशनल है

  • Iris samples 4-डायमेंशनल स्पेस में पॉइंट्स हैं
  • डायमेंशन = features की संख्या
  • डायमेंशन बहुत ज्यादा है, visualize नहीं कर सकते!
  • ... लेकिन unsupervised learning से insight मिलती है
Python में Unsupervised Learning

k-means clustering

  • Samples के clusters ढूँढ़ता है
  • क्लस्टर्स की संख्या पहले से देनी होती है
  • sklearn ("scikit-learn") में उपलब्ध
Python में Unsupervised Learning
print(samples)
[[ 5.   3.3  1.4  0.2]
 [ 5.   3.5  1.3  0.3]
 ...
 [ 7.2  3.2  6.   1.8]]
from sklearn.cluster import KMeans

model = KMeans(n_clusters=3)
model.fit(samples)
KMeans(n_clusters=3)
labels = model.predict(samples)

print(labels)
[0 0 1 1 0 1 2 1 0 1 ...]
Python में Unsupervised Learning

नए samples के cluster labels

  • नए samples को मौजूदा clusters में assign कर सकते हैं
  • k-means हर cluster का mean याद रखता है ("centroids")
  • हर नए sample के लिए सबसे नज़दीकी centroid ढूँढ़ता है
Python में Unsupervised Learning

नए samples के cluster labels

print(new_samples)
[[ 5.7  4.4  1.5  0.4]
 [ 6.5  3.   5.5  1.8]
 [ 5.8  2.7  5.1  1.9]]
new_labels = model.predict(new_samples)

print(new_labels)
[0 2 1]
Python में Unsupervised Learning

Scatter plots

  • Sepal length बनाम petal length का scatter plot
  • हर पॉइंट एक iris sample दर्शाता है
  • पॉइंट्स को cluster labels से color करें
  • PyPlot (matplotlib.pyplot)

Scatter plot

Python में Unsupervised Learning

Scatter plots

import matplotlib.pyplot as plt

xs = samples[:,0] ys = samples[:,2]
plt.scatter(xs, ys, c=labels)
plt.show()
Python में Unsupervised Learning

अभ्यास करते हैं!

Python में Unsupervised Learning

Preparing Video For Download...