मॉडल बनाएँ और आकलन करें: प्रोडक्ट रिव्यू डेटा
इस अभ्यास में, आप reviews डेटासेट पर लॉजिस्टिक रिग्रेशन बनाएँगे, जिसमें Amazon प्रोडक्ट्स के ग्राहकों के रिव्यू शामिल हैं. ऐरे y में sentiment है: पॉजिटिव होने पर 1 और अन्यथा 0. ऐरे X में BOW अप्रोच से बनाए गए सभी न्यूमेरिक फीचर्स हैं. आप चाहें तो इन्हें IPython Shell में एक्सप्लोर कर सकते हैं.
आपका कार्य है लॉजिस्टिक रिग्रेशन मॉडल बनाना और टेस्ट डेटासेट का उपयोग करके accuracy और confusion matrix निकालना.
लॉजिस्टिक रिग्रेशन और train/test splitting वाले फंक्शन आपके लिए पहले से इम्पोर्ट किए गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Sentiment Analysis
अभ्यास निर्देश
- accuracy score और confusion matrix फंक्शन इम्पोर्ट करें.
- डेटा को training और testing में बाँटें, जिसमें 30% डेटा test सेट हो और random seed
42रखें. - एक लॉजिस्टिक रिग्रेशन मॉडल train करें.
- टेस्ट डेटा का उपयोग करके accuracy score और confusion matrix प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the accuracy and confusion matrix
____
# Split the data into training and testing
X_train, X_test, y_train, y_test = ____(____, ____, ____=0.3, ____=42)
# Build a logistic regression
log_reg = ____._____
# Predict the labels
y_predict = log_reg.predict(X_test)
# Print the performance metrics
print('Accuracy score of test data: ', ____(____, ____))
print('Confusion matrix of test data: \n', ____(____, ____)/len(y_test))