tahatehrani commited on
Commit
751a568
·
verified ·
1 Parent(s): 30eb802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -22
app.py CHANGED
@@ -11,8 +11,6 @@ from pytz import timezone
11
  import plotly.graph_objects as go
12
  from sklearn.linear_model import LinearRegression
13
  from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
14
- from textblob.sentimiento import PatternAnalyzer
15
- from spacy.lang.en import English
16
  from sklearn.model_selection import train_test_split
17
  from sklearn.ensemble import RandomForestClassifier
18
  from sklearn.metrics import accuracy_score
@@ -92,37 +90,27 @@ def get_crypto_news(api_key, crypto_symbol, articles_count=10):
92
  else:
93
  return []
94
 
95
- def analyze_news_sentiment(news, customized_thresholds=None, domain_lexicon=None):
96
- if domain_lexicon is None:
97
- # Use a default sentiment analyzer
98
- analyzer = SentimentIntensityAnalyzer()
99
- else:
100
- # Use a custom sentiment analyzer with domain-specific lexicon
101
- nlp = English()
102
- nlp.add_pipe("textblob_sentiment", config={"lexicon": domain_lexicon})
103
- analyzer = nlp.get_pipe("textblob_sentiment")
104
-
105
- if customized_thresholds is None:
106
- customized_thresholds = {
107
- "positive": 0.5,
108
- "negative": -0.5,
109
- "neutral": 0.1
110
- }
111
-
112
  for article in news:
113
  title = article['title']
114
  description = article['description']
115
  sentiment_score = analyzer.polarity_scores(title + " " + description)
116
 
117
- if sentiment_score['compound'] >= customized_thresholds['positive']:
 
 
 
 
 
118
  article['sentiment'] = 'positive'
119
- elif sentiment_score['compound'] <= customized_thresholds['negative']:
120
  article['sentiment'] = 'negative'
121
  else:
122
  article['sentiment'] = 'neutral'
123
 
124
  return news
125
-
126
  def train_price_prediction_model(data):
127
  X = data[['Open', 'High', 'Low', 'Volume']]
128
  y = data['Close']
 
11
  import plotly.graph_objects as go
12
  from sklearn.linear_model import LinearRegression
13
  from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
 
 
14
  from sklearn.model_selection import train_test_split
15
  from sklearn.ensemble import RandomForestClassifier
16
  from sklearn.metrics import accuracy_score
 
90
  else:
91
  return []
92
 
93
+ def custom_sentiment_analysis(news, domain_lexicon):
94
+ analyzer = SentimentIntensityAnalyzer()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  for article in news:
96
  title = article['title']
97
  description = article['description']
98
  sentiment_score = analyzer.polarity_scores(title + " " + description)
99
 
100
+ # Use the domain-specific lexicon to adjust the sentiment score
101
+ for term, weight in domain_lexicon.items():
102
+ if term.lower() in (title + " " + description).lower():
103
+ sentiment_score['compound'] += weight
104
+
105
+ if sentiment_score['compound'] >= 0.5:
106
  article['sentiment'] = 'positive'
107
+ elif sentiment_score['compound'] <= -0.5:
108
  article['sentiment'] = 'negative'
109
  else:
110
  article['sentiment'] = 'neutral'
111
 
112
  return news
113
+
114
  def train_price_prediction_model(data):
115
  X = data[['Open', 'High', 'Low', 'Volume']]
116
  y = data['Close']