From 7b2aa494d3086e81e8a2a16d31927399d66d5428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=CD=A1urendra=20S=CD=A1id=20-=20AR?= <105810226+AR-sslink@users.noreply.github.com> Date: Thu, 14 Sep 2023 00:24:27 +0530 Subject: [PATCH 1/2] Create Machine Learning - Sentiment Analysis ## Machine learning Sentiment Analysis: sentiment analysis model that can analyze and classify text data (e.g., tweets, product reviews) as positive, negative, or neutral sentiment. --- Machine Learning - Sentiment Analysis | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Machine Learning - Sentiment Analysis diff --git a/Machine Learning - Sentiment Analysis b/Machine Learning - Sentiment Analysis new file mode 100644 index 000000000000..91db4c9ed1de --- /dev/null +++ b/Machine Learning - Sentiment Analysis @@ -0,0 +1,30 @@ +import nltk +from nltk.sentiment.vader import SentimentIntensityAnalyzer + +# Download VADER lexicon (if not already downloaded) +nltk.download('vader_lexicon') + +# Initialize the sentiment analyzer +sid = SentimentIntensityAnalyzer() + +def analyze_sentiment(text): + # Calculate sentiment scores + sentiment_scores = sid.polarity_scores(text) + + # Determine sentiment label based on the compound score + compound_score = sentiment_scores['compound'] + if compound_score >= 0.05: + return "Positive" + elif compound_score <= -0.05: + return "Negative" + else: + return "Neutral" + +# Input text for analysis +text = "I love this product! It's amazing." + +# Perform sentiment analysis +sentiment = analyze_sentiment(text) + +# Display the sentiment result +print(f"Sentiment: {sentiment}") From 90785deb902da2702c9319372a1b8423e5b05ab7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:58:23 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Machine Learning - Sentiment Analysis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Machine Learning - Sentiment Analysis b/Machine Learning - Sentiment Analysis index 91db4c9ed1de..7003857427a2 100644 --- a/Machine Learning - Sentiment Analysis +++ b/Machine Learning - Sentiment Analysis @@ -10,7 +10,7 @@ sid = SentimentIntensityAnalyzer() def analyze_sentiment(text): # Calculate sentiment scores sentiment_scores = sid.polarity_scores(text) - + # Determine sentiment label based on the compound score compound_score = sentiment_scores['compound'] if compound_score >= 0.05: