This project aims to predict the sentiment (positive or negative) from financial news headlines using machine learning techniques.
Install FinanceSentimentAnalyzer
using pip
:
pip install git+https://github.com/MatthewW05/FinanceSentimentAnalyzer.git
Required dependencies , All dependencies.
from FinanceSentimentAnalyzer import predict_headline_sentiment
headline = "Nvidia Stock Rises. How Earnings From Microsoft and Apple Could Drive It Higher."
# by default a pre-trained model is pre-loaded when imported
# the function will return float between 0 and 1
prediction = predict_headline_sentiment(headline)
prediction = "Positive" if round(prediction) == 1 else "Negative"
print(f"Prediction for \'{headline}\': {prediction}")
When loading your own model, you must include both the model and and the used vocabulary
from FinanceSentimentAnalyzer import load_model_and_vocab, predict_headline_sentiment
headline = "Nvidia Stock Rises. How Earnings From Microsoft and Apple Could Drive It Higher."
model, vocab = load_model_and_vocab('path/to/your/model', 'path/to/your/vocab')
prediction = predict_headline_sentiment(headline, model, vocab)
prediction = "Positive" if round(prediction) == 1 else "Negative"
print(f"Prediction for \'{headline}\': {prediction}")
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project uses data from several third-party sources. We acknowledge and thank the creators of these datasets:
- Sentiment Analysis for Financial News - Ankur Sinha
- Financial Sentiment Analysis - sbhatti
- Sentiment Analysis - Labelled Financial News Data - Arav Sood7
- financial_phrasebank - Ankur Sinha
- Aspect based Sentiment Analysis for Financial News - Ankur Sinha
This project is licensed under the MIT License. See the LICENSE file for details.
Matthew Wong