Skip to content

Instantly share code, notes, and snippets.

View Raviraj2000's full-sized avatar

Raviraj Shinde Raviraj2000

View GitHub Profile
@Raviraj2000
Raviraj2000 / DataProcessingImport.py
Created October 10, 2021 06:22
DataProcessingImport()
import numpy as np
import pandas as pd
@Raviraj2000
Raviraj2000 / loadcsv.py
Created October 10, 2021 06:28
LoadCSV()
finance_news = pd.read_csv('news.csv', encoding = 'ISO-8859-1')
finance_news.head()
@Raviraj2000
Raviraj2000 / separatedata.py
Last active October 10, 2021 06:43
SeparateData()
X = finance_news['headline'].to_list()
y = finance_news['sentiment'].to_list()
@Raviraj2000
Raviraj2000 / loadfinbert.py
Created October 10, 2021 07:04
LoadFinBERT
from transformers import BertTokenizer, BertForSequenceClassification
finbert = BertForSequenceClassification.from_pretrained('yiyanghkust/finbert-tone',num_labels=3)
tokenizer = BertTokenizer.from_pretrained('yiyanghkust/finbert-tone')
@Raviraj2000
Raviraj2000 / sentdict.py
Created October 10, 2021 07:52
SentDict
labels = {0:'neutral', 1:'positive',2:'negative'}
@Raviraj2000
Raviraj2000 / getsent.py
Created October 10, 2021 07:54
GetSent
sent_val = list()
for x in X:
inputs = tokenizer(x, return_tensors="pt", padding=True)
outputs = finbert(**inputs)[0]
val = labels[np.argmax(outputs.detach().numpy())]
print(x, '----', val)
print('#######################################################')
sent_val.append(val)
@Raviraj2000
Raviraj2000 / getaccuracy.py
Created October 10, 2021 08:16
GetAccuracy
from sklearn.metrics import accuracy_score
print(accuracy_score(y, sent_val))
@Raviraj2000
Raviraj2000 / webscrapeimports.py
Created October 10, 2021 19:02
WebScrapeImport()
from bs4 import BeautifulSoup
import pandas as pd
from urllib.request import urlopen, Request
@Raviraj2000
Raviraj2000 / getticks.py
Last active October 10, 2021 19:16
GetTicks()
def get_ticks(url):
req = Request(url=url,headers={"User-Agent": "Chrome"})
response = urlopen(req)
html = BeautifulSoup(response,"html.parser")
ticks_table = html.find(class_ = 'page')
ticks = list()
stocks = list()
for name_box in ticks_table.find_all('a', href = True):
stocks.append(name_box.text.strip())
@Raviraj2000
Raviraj2000 / gotticks.py
Last active October 10, 2021 19:19
gotticks()
url = "https://www.tickertape.in/stocks"
tick_df = get_ticks(url)
tick_df.head()