Algorithmically predict public sentiment on a topic using VADER sentiment analysis
Project description
abraham
Algorithmically predict public sentiment on a topic using VADER sentiment analysis.
Installation
Installation is simple; just install via pip.
$ pip3 install abraham3k
Basic Usage
You can run one command to do everything
from prophets import Isaiah
darthvader = Isaiah(news_source="google")
scores = darthvader.sentiment(["amd",
"microsoft",
"tesla",
"theranos"],
window=2)
print(scores)
'''
{'amd': {'avg': 0.32922767,
'desc_avg': 0.40470959,
'info': {'news_source': 'google',
'splitting': False,
'weights': {'desc': 0.1, 'text': 0.8, 'title': 0.1}},
'nice': 'positive',
'text_avg': 0.31924348,
'title_avg': 0.3336193},
'microsoft': {'avg': 0.22709808,
'desc_avg': 0.35126282,
'info': {'news_source': 'google',
'splitting': False,
'weights': {'desc': 0.1, 'text': 0.8, 'title': 0.1}},
'nice': 'positive',
'text_avg': 0.22539444,
'title_avg': 0.1165625},
'tesla': {'avg': -0.20538455,
'desc_avg': -0.22413444,
'info': {'news_source': 'google',
'splitting': False,
'weights': {'desc': 0.1, 'text': 0.8, 'title': 0.1}},
'nice': 'negative',
'text_avg': -0.19356265,
'title_avg': -0.28120986},
'theranos': {'avg': -0.036198,
'desc_avg': 0.03842,
'info': {'news_source': 'google',
'splitting': False,
'weights': {'desc': 0.1, 'text': 0.8, 'title': 0.1}},
'nice': 'neutral',
'text_avg': -0.08745,
'title_avg': 0.2992}}
'''
Changing News Sources
Isaiah
supports two news sources: Google News and NewsAPI. Default is Google News, but you can change it to NewsAPI by passing Isaiah(news_source='newsapi', api_key='<your api key')
when instantiating. I'd highly recommend using NewsAPI. It's much better than the Google News API. Setup is really simple, just head to the register page and sign up to get your API key.
Detailed Usage
Currently, there are a couple extra options you can use to tweak the output.
When instatiating the class, you can pass up to five optional keyword arguments: news_source
and api_key
(as explained above), splitting
, and weights
.
loud
:bool
- Whether or not the classifier prints out each individual average or not. Default:False
.splitting
:bool
- Recursively splits a large text into sentences and analyzes each sentence individually, rather than examining the article as a block. Default:False
.weights
:dict
- This chooses what each individual category (text
,title
,desc
) is weighted as (must add up to 1). Default:weights={"title": 0.1, "desc": 0.1, "text": 0.8}
.
When running the main function, sentiment
, there is one requred argument, topics
, and two optional keyword arguments: window
and up_to
.
topics
:list
- The list of the topics (each astr
) to search for.up_to
:str
- The latest day to search for, in formatYYYY-MM-DD
. Default: current date.window
:int
- How many days back fromup_to
to search for. Default2
.
Updates
I've made it pretty simple (at least for me) to push updates. Once I'm in the directory, I can run $ ./build-push 1.2.0 "update install requirements"
where 1.2.0
is the version and "update install requirements"
is the git commit message. It will update to PyPi and to the github repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file abraham3k-1.2.3.tar.gz
.
File metadata
- Download URL: abraham3k-1.2.3.tar.gz
- Upload date:
- Size: 5.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbc5a45259c6e4d405503e658589554f22a97986506d6f92a58fcc28be903243 |
|
MD5 | 593341a9cb0f648b0a8995e73b17f8b7 |
|
BLAKE2b-256 | 62a9dcde651c0f2531b015b5d465c0a2b67b799ef036206eca927d68b667e37f |
File details
Details for the file abraham3k-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: abraham3k-1.2.3-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3719a2dded7992f1ac998971e95f0d69c1b893c9e00cfdeb2f2c5971fca66279 |
|
MD5 | 9eb62105d216cd92367b98cb9c1b8640 |
|
BLAKE2b-256 | c2b56b35bbcc1d6b482a71b0c6bf9d964fb40fa2659f0568e3ccf291e4555654 |