क्लासिफिकेशन-ट्री लर्निंग

Python में Tree-Based Models के साथ Machine Learning

Elie Kawerk

Data Scientist

Decision-Tree के बिल्डिंग ब्लॉक्स

  • Decision-Tree: नोड्स की पदानुक्रम वाली डेटा संरचना.

  • Node: प्रश्न या भविष्यवाणी.

Python में Tree-Based Models के साथ Machine Learning

Decision-Tree के बिल्डिंग ब्लॉक्स

नोड्स के तीन प्रकार:

  • Root: कोई parent नहीं, प्रश्न जिससे दो child नोड बनते हैं.

  • Internal node: एक parent, प्रश्न जिससे दो child नोड बनते हैं.

  • Leaf: एक parent, कोई child नहीं --> भविष्यवाणी.

Python में Tree-Based Models के साथ Machine Learning

भविष्यवाणी

DT-labeled

Python में Tree-Based Models के साथ Machine Learning

Information Gain (IG)

IG-diagram

Python में Tree-Based Models के साथ Machine Learning

Information Gain (IG)

IG-formula

नोड की अशुद्धि मापने के मापदंड $I (node)$:

  • gini index,
  • entropy. ...
Python में Tree-Based Models के साथ Machine Learning

क्लासिफिकेशन-ट्री लर्निंग

  • नोड्स को recursively grow किया जाता है.

  • हर नोड पर डेटा को इस आधार पर split करें:

    • फीचर $f$ और split-point $sp$ ताकि $IG(\text{node})$ अधिकतम हो.
  • यदि $IG (\text{node})$ = 0, तो नोड को leaf घोषित करें.

    ...

Python में Tree-Based Models के साथ Machine Learning
# Import DecisionTreeClassifier
from sklearn.tree import DecisionTreeClassifier
# Import train_test_split
from sklearn.model_selection import train_test_split
# Import accuracy_score
from sklearn.metrics import accuracy_score
# Split dataset into 80% train, 20% test
X_train, X_test, y_train, y_test= train_test_split(X, y, 
                                                   test_size=0.2, 
                                                   stratify=y,
                                                   random_state=1)
# Instantiate dt, set 'criterion' to 'gini'
dt = DecisionTreeClassifier(criterion='gini', random_state=1)
Python में Tree-Based Models के साथ Machine Learning

scikit-learn में Information Criterion

# Fit dt to the training set
dt.fit(X_train,y_train)

# Predict test-set labels
y_pred= dt.predict(X_test)

# Evaluate test-set accuracy
accuracy_score(y_test, y_pred)
0.92105263157894735
Python में Tree-Based Models के साथ Machine Learning

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

Python में Tree-Based Models के साथ Machine Learning

Preparing Video For Download...