डिसीजन ट्री से churn की भविष्यवाणी

Python में मार्केटिंग के लिए मशीन लर्निंग

Karolis Urbonas

Head of Analytics & Science, Amazon

डिसीजन ट्री परिचय

टाइटैनिक सर्वाइवल डेटासेट पर डिसीजन ट्री के नियम

Python में मार्केटिंग के लिए मशीन लर्निंग

मॉडलिंग स्टेप्स

  1. डेटा को training और testing में विभाजित करें
  2. मॉडल को initialize करें
  3. प्रशिक्षण डेटा पर मॉडल fit करें
  4. testing डेटा पर मान predict करें
  5. testing डेटा पर मॉडल का performance मापें
Python में मार्केटिंग के लिए मशीन लर्निंग

मॉडल फिट करना

डिसीजन ट्री मॉड्यूल import करें

from sklearn.tree import DecisionTreeClassifier

Decision Tree मॉडल initialize करें

mytree = DecisionTreeClassifier()

प्रशिक्षण डेटा पर मॉडल fit करें

treemodel = mytree.fit(train_X, train_Y)
Python में मार्केटिंग के लिए मशीन लर्निंग

मॉडल की accuracy मापना

from sklearn.metrics import accuracy_score

pred_train_Y = mytree.predict(train_X) pred_test_Y = mytree.predict(test_X)
train_accuracy = accuracy_score(train_Y, pred_train_Y) test_accuracy = accuracy_score(test_Y, pred_test_Y)
print('Training accuracy:', round(train_accuracy,4)) print('Test accuracy:', round(test_accuracy, 4))
Training accuracy: 0.9973
Test accuracy: 0.7196
Python में मार्केटिंग के लिए मशीन लर्निंग

Precision और recall मापना

from sklearn.metrics import precision_score, recall_score

train_precision = round(precision_score(train_Y, pred_train_Y), 4) test_precision = round(precision_score(test_Y, pred_test_Y), 4)
train_recall = round(recall_score(train_Y, pred_train_Y), 4) test_recall = round(recall_score(test_Y, pred_test_Y), 4)
print('Training precision: {}, Training recall: {}'.format(train_precision, train_recall)) print('Test precision: {}, Test recall: {}'.format(train_recall, test_recall))
Training precision: 0.9993, Training recall: 0.9906
Test precision: 0.9906, Test recall: 0.4878
Python में मार्केटिंग के लिए मशीन लर्निंग

ट्री depth पैरामीटर ट्यूनिंग

depth_list = list(range(2,15))
depth_tuning = np.zeros((len(depth_list), 4))
depth_tuning[:,0] = depth_list

for index in range(len(depth_list)): mytree = DecisionTreeClassifier(max_depth=depth_list[index]) mytree.fit(train_X, train_Y) pred_test_Y = mytree.predict(test_X)
depth_tuning[index,1] = accuracy_score(test_Y, pred_test_Y) depth_tuning[index,2] = precision_score(test_Y, pred_test_Y) depth_tuning[index,3] = recall_score(test_Y, pred_test_Y)
col_names = ['Max_Depth','Accuracy','Precision','Recall'] print(pd.DataFrame(depth_tuning, columns=col_names))
Python में मार्केटिंग के लिए मशीन लर्निंग

सर्वोत्तम depth चुनना

Max Depth ट्यूनिंग

Python में मार्केटिंग के लिए मशीन लर्निंग

सर्वोत्तम depth चुनना

Max Depth ट्यूनिंग

Python में मार्केटिंग के लिए मशीन लर्निंग

आइए एक डिसीजन ट्री बनाते हैं!

Python में मार्केटिंग के लिए मशीन लर्निंग

Preparing Video For Download...