tobby48 5 years ago
parent
commit
f7c5130bb2

+ 32
- 17
src/main/python/kr/co/swh/lecture/opensource/stock/2-analysis-krx-Linear-Regression.py View File

@@ -1,15 +1,30 @@
1
+# 오류 error: Microsoft Visual C++ 14.0 is required
2
+# 따라서 구글에서 검색해서 설치
3
+# conda create -n py36 python=3.6
4
+# pip3 install torch===1.3.1 torchvision===0.4.2 -f https://download.pytorch.org/whl/torch_stable.html
5
+
1 6
 from sqlalchemy import create_engine
2 7
 import pymysql
3 8
 import pandas as pd
4 9
 import numpy as np
5 10
 
6
-pymysql.install_as_MySQLdb()
7
-engine = create_engine("mysql+mysqldb://root:"+"tokki1127"+"@127.0.0.1/stock", encoding='utf-8')
8
-conn = engine.connect()
11
+#pymysql.install_as_MySQLdb()
12
+#engine = create_engine("mysql+mysqldb://root:"+"tokki1127"+"@127.0.0.1/stock", encoding='utf-8')
13
+#conn = engine.connect()
14
+
15
+#df = pd.read_sql_query("select * from stock_trade where 종목코드 = '000660'", conn)
16
+#df.name = "주가변동"
17
+#print(df.head())
18
+
19
+df = pd.read_csv('skhynix.csv')
20
+print(df.head(5))
21
+
22
+# 종목코드 left zero padding 설정
23
+df['종목코드'] = df['종목코드'].apply(lambda x: "{:0>6d}".format(x))
24
+df.head(5)
25
+
26
+
9 27
 
10
-df = pd.read_sql_query("select * from stock_trade where 종목코드 = '000660'", conn)
11
-df.name = "주가변동"
12
-print(df.head())
13 28
 
14 29
 
15 30
 # 인덱스 확인 (그래프의 X축 : DB로 부터 읽어온 값은 DataFrame으로 불러올 시, 0부터 숫자가 붙어있음)
@@ -37,21 +52,21 @@ for i in range(0,len(df)):
37 52
      new_data['종가'][i] = df['종가'][i]
38 53
 print(new_data.head())  # 날짜와 종가에 대한 데이터
39 54
 
40
-# !pip install sklearn
55
+# !pip install scikit-learn
41 56
 
42 57
 # fastai.structured import에서 기능 생성 add_datepart
43 58
 # !pip install fastai==0.7.0
44 59
 # 설치가 잘 되지 않음 
45
-#from fastai.structured import  add_datepart
46
-#add_datepart (new_data, 'Date')
60
+from fastai.structured import  add_datepart
61
+add_datepart (new_data, 'Date')
47 62
 # 대신 아래와 같이 코딩
48 63
 
49 64
 #new_data = new_data.copy()
50
-new_data['mon_fri'] = 0
51
-print(new_data.head())
52
-for i in range(0,len(new_data)):
53
-    if (new_data['Dayofweek'][i] == 0 or new_data['Dayofweek'][i] == 4):
54
-        new_data['mon_fri'][i] = 1
55
-    else:
56
-        new_data['mon_fri'][i] = 0 
57
-new_data.drop ( 'Elapsed', axis = 1, inplace = True) #elapsed는 타임 스탬프가됩니다
65
+#new_data['mon_fri'] = 0
66
+#print(new_data.head())
67
+#for i in range(0,len(new_data)):
68
+    #if (new_data['Dayofweek'][i] == 0 or new_data['Dayofweek'][i] == 4):
69
+        #new_data['mon_fri'][i] = 1
70
+    #else:
71
+        #new_data['mon_fri'][i] = 0 
72
+#new_data.drop ( 'Elapsed', axis = 1, inplace = True) #elapsed는 타임 스탬프가됩니다