चलते-चलते शुरू करें! Polarity को विज़ुअलाइज़ करें
Sentiment analysis यह समझने में मदद करती है कि लेखक किसी विषय के बारे में कैसा महसूस करता है. यह अभ्यास आपको आगे आने वाले कॉन्सेप्ट्स की शुरुआती झलक देगा!
हमने person और text कॉलम के साथ एक conversation को दर्शाते हुए text_df बनाया है.
qdap का polarity() फंक्शन इस्तेमाल करके text_df को स्कोर करें. polarity() या तो एक single character ऑब्जेक्ट स्वीकार करता है या फिर एक data frame जिसमें कोई grouping वैरिएबल हो, ताकि positive या negative स्कोर निकाला जा सके.
इस उदाहरण में आप magrittr पैकेज का dollar pipe ऑपरेटर %$% इस्तेमाल करेंगे. Dollar साइन data frame को polarity() में forward करता है, और आप text कॉलम का नाम या text कॉलम के साथ-साथ एक grouping वैरिएबल बिना quotes दिए बताते हैं.
text_data_frame %$% polarity(text_column_name)
Dollar साइन ऑपरेटर के साथ एक ऑब्जेक्ट बनाने के लिए:
polarity_object <- text_data_frame %$%
polarity(text_column_name, grouping_column_name)
और स्पष्ट रूप से कहें तो, किसी टेक्स्ट के sentiment पर quantitative निर्णय लेने के लिए उसे कोई स्कोर देना होता है. एक सरल तरीका है कि वाक्य, अनुच्छेद, या दस्तावेज़ों के संग्रह (corpus) के लिए positive या negative मान दिए जाएँ. केवल positive या negative मानों से स्कोर करना "polarity" कहलाता है. Polarity स्कोर निकालने के लिए एक उपयोगी फंक्शन counts() है, जिसे polarity ऑब्जेक्ट पर लगाया जाता है. त्वरित visualization के लिए polarity() के परिणाम पर plot() कॉल करें.
यह अभ्यास पाठ्यक्रम का हिस्सा है
R में Sentiment Analysis
अभ्यास निर्देश
text_dfconversation data frame की जाँच करें.%$%का उपयोग करकेtext_dfकोpolarity()में पास करें और कॉलम नामtextको बिना quotes दें. इससे पूरे टेक्स्ट की polarity प्रिंट होगी.- एक नया ऑब्जेक्ट
datacamp_conversationबनाएँ:%$%सेtext_dfकोpolarity()में forward करें.textदें और उसके बाद grouping के लिएpersonकॉलम दें. इससे प्रत्येक व्यक्ति के अनुसार polarity निकलेगी. चूँकि सब कुछ parentheses के भीतर है, परिणाम भी प्रिंट होगा. - मिले हुए विशिष्ट भावनात्मक शब्दों को प्रिंट करने के लिए
datacamp_conversationपरcounts()लगाएँ. datacamp_conversationकोplot()करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Examine the text data
text_df
# Calc overall polarity score
text_df %$% polarity(___)
# Calc polarity score by person
(datacamp_conversation <- text_df %$% ___(___, ___))
# Counts table from datacamp_conversation
___(___)
# Plot the conversation polarity
___(___)