लॉजिस्टिक रिग्रेशन

PySpark के साथ Machine Learning

Andrew Collier

Data Scientist, Fathom Data

लॉजिस्टिक कर्व

एक लॉजिस्टिक कर्व.

PySpark के साथ Machine Learning

लॉजिस्टिक कर्व

थ्रेशोल्ड से ऊपर शेडिंग वाला लॉजिस्टिक कर्व

PySpark के साथ Machine Learning

लॉजिस्टिक कर्व

थ्रेशोल्ड से नीचे शेडिंग वाला लॉजिस्टिक कर्व

PySpark के साथ Machine Learning

लॉजिस्टिक कर्व

दाएँ शिफ्ट किया गया लॉजिस्टिक कर्व

PySpark के साथ Machine Learning

लॉजिस्टिक कर्व

बाएँ शिफ्ट किया गया लॉजिस्टिक कर्व

PySpark के साथ Machine Learning

लॉजिस्टिक कर्व

धीमे ट्रांजिशन वाला लॉजिस्टिक कर्व

PySpark के साथ Machine Learning

लॉजिस्टिक कर्व

तेज़ ट्रांजिशन वाला लॉजिस्टिक कर्व

PySpark के साथ Machine Learning

Cars पुनरावलोकन

मॉडलिंग की तैयारी:

  • सभी predictors को एक कॉलम (features) में जोड़ें और
  • डेटा को training और testing सेट में बाँटें.
+---+----+------+------+----+-----------+----------------------------------+-----+
|cyl|size|mass  |length|rpm |consumption|features                          |label|
+---+----+------+------+----+-----------+----------------------------------+-----+
|6  |3.0 |1451.0|4.775 |5200|9.05       |[6.0,3.0,1451.0,4.775,5200.0,9.05]|1.0  |
|4  |2.2 |1129.0|4.623 |5200|6.53       |[4.0,2.2,1129.0,4.623,5200.0,6.53]|0.0  |
|4  |2.2 |1399.0|4.547 |5600|7.84       |[4.0,2.2,1399.0,4.547,5600.0,7.84]|1.0  |
|4  |1.8 |1147.0|4.343 |6500|7.84       |[4.0,1.8,1147.0,4.343,6500.0,7.84]|0.0  |
|4  |1.6 |1111.0|4.216 |5750|9.05       |[4.0,1.6,1111.0,4.216,5750.0,9.05]|0.0  |
+---+----+------+------+----+-----------+----------------------------------+-----+
PySpark के साथ Machine Learning

Logistic Regression मॉडल बनाएँ

from pyspark.ml.classification import LogisticRegression

एक Logistic Regression क्लासिफायर बनाएँ.

logistic = LogisticRegression()

training डेटा से सीखें.

logistic = logistic.fit(cars_train)
PySpark के साथ Machine Learning

प्रेडिक्शंस

prediction = logistic.transform(cars_test)
+-----+----------+---------------------------------------+
|label|prediction|probability                            |
+-----+----------+---------------------------------------+
|0.0  |0.0       |[0.8683802216422138,0.1316197783577862]|
|0.0  |1.0       |[0.1343792056399585,0.8656207943600416]|
|0.0  |0.0       |[0.9773546766387631,0.0226453233612368]|
|1.0  |1.0       |[0.0170508265586195,0.9829491734413806]|
|1.0  |0.0       |[0.6122241729292978,0.3877758270707023]|
+-----+----------+---------------------------------------+
PySpark के साथ Machine Learning

Precision और Recall

मॉडल testing डेटा पर कितना अच्छा काम करता है?

confusion matrix देखें.

+-----+----------+-----+
|label|prediction|count|
+-----+----------+-----+
|  1.0|       1.0|    8| - TP (true positive)
|  0.0|       1.0|    4| - FP (false positive)
|  1.0|       0.0|    2| - FN (false negative)
|  0.0|       0.0|   10| - TN (true negative)
+-----+----------+-----+
# Precision (positive)
TP / (TP + FP)
0.6666666666666666
# Recall (positive)
TP / (TP + FN)
0.8
PySpark के साथ Machine Learning

Weighted metrics

from pyspark.ml.evaluation import MulticlassClassificationEvaluator

evaluator = MulticlassClassificationEvaluator()

evaluator.evaluate(prediction, {evaluator.metricName: 'weightedPrecision'})
0.7638888888888888

अन्य metrics:

  • weightedRecall
  • accuracy
  • f1
PySpark के साथ Machine Learning

ROC और AUC

एक ROC कर्व

ROC = "Receiver Operating Characteristic"

  • TP बनाम FP
  • threshold = 0 (ऊपर दाएँ)
  • threshold = 1 (नीचे बाएँ)

AUC = "Area under the curve"

  • आदर्श रूप से AUC = 1
PySpark के साथ Machine Learning

आइए Logistic Regression करें!

PySpark के साथ Machine Learning

Preparing Video For Download...