-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_image.py
65 lines (54 loc) · 1.58 KB
/
create_image.py
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
import numpy as np
from PIL import Image
import pandas as pd
import os
import matplotlib.pyplot as plt
def make_image(array):
data = Image.fromarray(array)
return data
def get_labels(data):
data_array = data["Close"].to_numpy()
labels = np.array([0 for i in range(len(data_array))]).astype("uint8")
for i in range(0,len(data_array)-16,1):
window = data_array[i:i+15]
minindex = np.argmin(window)
maxindex = np.argmax(window)
labels[i + minindex] = 1
labels[i + maxindex] = 2
return labels
df = pd.read_csv("data.csv")
df.drop('Date', axis=1, inplace=True)
np_array = df.to_numpy()
labels = get_labels(df)
root = 'D:/Programing/Python/Image procesing in Finance/Data/BHARTIARTL/' # root data path
buy = root + 'Buy'
sell = root + 'Sell'
hold = root + 'Hold'
try:
os.mkdir(buy)
except:
print("Directory alredy exist or OSError")
try:
os.mkdir(sell)
except:
print("Directory alredy exist or OSError")
try:
os.mkdir(hold)
except:
print("Directory alredy exist or OSError")
for i in range(0,np.shape(np_array)[0]-14):
img = np_array[i:i+15]
img = np.transpose(img)
for j in range (0,15):
img[j] = (img[j]- np.min(img[j]))/(np.max(img[j]))
img[j] = np.abs(img[j])
img = np.round(img*255)
img.reshape((15,15,1))
img = img.astype('int')
img = make_image(img)
if (labels[i] == 0):
img.save(hold+'/img' +str(i)+'.png')
if (labels[i] == 1):
img.save(buy+'/img' +str(i)+'.png')
if (labels[i] == 2):
img.save(sell+'/img' +str(i)+'.png')