-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (53 loc) · 1.8 KB
/
main.py
File metadata and controls
69 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pandas as pd
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from yahoo import fetch_yahoo
import warnings
from time import sleep
warnings.filterwarnings('ignore')
# reading the data
df = pd.read_csv('HSI.csv')
df.dropna(inplace=True)
# Split dataset
x = df.iloc[:, 2:4]
y = df.iloc[:, 8]
validation_size = 0.20
seed = 7
# Use only training data
X_train, X_validation, Y_train, Y_validation = model_selection.train_test_split(x, y, test_size=validation_size, random_state=seed)
def train_accuracy():
# Test options and evaluation metric
seed = 7
scoring = 'accuracy'
# Spot Check Algorithms
models = []
models.append(('LR', LogisticRegression(solver='liblinear', multi_class='ovr')))
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('CART', DecisionTreeClassifier()))
# evaluate each model in turn
results = []
names = []
for name, model in models:
kfold = model_selection.KFold(n_splits=10, random_state=seed)
cv_results = model_selection.cross_val_score(model, X_train, Y_train, cv=kfold, scoring=scoring)
results.append(cv_results)
names.append(name)
msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
print(msg)
def predict():
new_x = fetch_yahoo()
data_x = pd.DataFrame(data=new_x)
data_x.set_index('Open', inplace=True)
lr = LogisticRegression()
lr.fit(X_train, Y_train)
prediction = lr.predict(data_x)
prediction_str = ''
if prediction == 1:
prediction_str = 'RISE'
else:
prediction_str = 'FALL'
print('HSI is expected to %s today!' % prediction_str)
predict()
sleep(3)