शुरू करेंमुफ़्त में शुरू करें

Logistic Regression मॉडल प्रशिक्षण

डेटा के लिए लेबल्स और फीचर्स बनाने के बाद, अब हम ऐसा मॉडल बनाने के लिए तैयार हैं जो उनसे सीख सके (training). लेकिन मॉडल ट्रेन करने से पहले, इस अभ्यास के अंतिम भाग में, आप डेटा को training और test में बाँटेंगे, training डेटा पर Logistic Regression मॉडल चलाएँगे, और अंत में training डेटा पर प्रशिक्षित मॉडल की accuracy जाँचेंगे.

ध्यान रखें, आपके workspace में SparkContext sc उपलब्ध है, साथ ही samples वैरिएबल भी.

यह अभ्यास पाठ्यक्रम का हिस्सा है

PySpark के साथ Big Data Fundamentals

पाठ्यक्रम देखें

अभ्यास निर्देश

  • संयुक्त डेटा को 80:20 अनुपात में training और test डेटासेट्स में बाँटें.
  • training डेटासेट के साथ Logistic Regression मॉडल को train करें.
  • test डेटासेट पर trained मॉडल से prediction लेबल बनाएँ.
  • zip फंक्शन का उपयोग करके test डेटासेट के लेबल्स को prediction डेटासेट के लेबल्स के साथ मिलाएँ.
  • original और predicted लेबल्स का उपयोग करके trained मॉडल की accuracy निकालें और उसे प्रिंट करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Split the data into training and testing
train_samples,test_samples = samples.____([0.8, 0.2])

# Train the model
model = LogisticRegressionWithLBFGS.train(____)

# Create a prediction label from the test data
predictions = model.____(test_samples.map(lambda x: x.features))

# Combine original labels with the predicted labels
labels_and_preds = test_samples.map(lambda x: x.label).zip(____)

# Check the accuracy of the model on the test data
accuracy = labels_and_preds.filter(lambda x: x[0] == x[____]).count() / float(test_samples.count())
print("Model accuracy : {:.2f}".format(____))
कोड संपादित करें और चलाएँ