Skip to content

Commit

Permalink
Merge pull request #82 from CSID-DGU/develop
Browse files Browse the repository at this point in the history
Develop to Main
  • Loading branch information
bbbang105 authored Jun 24, 2024
2 parents aec7ae1 + ec2030a commit 7e6d72a
Show file tree
Hide file tree
Showing 424 changed files with 34,109 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/-issue-생성-템플릿.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "\bIssue 생성 템플릿"
about: 해당 Issue 생성 템플릿을 통하여 Issue를 생성해주세요.
title: 'ex) 깃모지 [feat] : Issue 제목'
labels: ''
assignees: ''

---

### 📝 Description

- 구현할 내용 1
- 구현할 내용 2

---

### 📝 Todo

- [ ] 구현할 내용 1
- [ ] 구현할 내용 2
37 changes: 37 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## ✅ PR 유형
어떤 변경 사항이 있었나요?

- [ ] 새로운 기능 추가
- [ ] 버그 수정
- [ ] 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
- [ ] 코드 리팩토링
- [ ] 주석 추가 및 수정
- [ ] 문서 수정
- [ ] 빌드 부분 혹은 패키지 매니저 수정
- [ ] 파일 혹은 폴더명 수정
- [ ] 파일 혹은 폴더 삭제

---

## 📝 작업 내용
이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

- 작업한 내용 1
- 작업한 내용 2

---

## ✏️ 관련 이슈
본인이 작업한 내용이 어떤 Issue Number와 관련이 있는지만 작성해주세요

ex)
- Fixes : #00 (수정중인 이슈)
- Resolves : #100 (무슨 이슈를 해결했는지)
- Ref : #00 #01 (참고할 이슈)
- Related to : #00 #01 (해당 커밋과 관려)

---

## 🎸 기타 사항 or 추가 코멘트


58 changes: 58 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: owl CI/CD with Gradle

on:
push:
branches: [ "main", "develop" ]
paths:
- 'backend/**'
pull_request:
branches: [ "main", "develop" ]
paths:
- 'backend/**'

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: 🦉 Checkout code
uses: actions/checkout@v3

- name: 🦉 Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: 🦉 Gradle Caching - 빌드 시간 향상
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 🦉 gradle build를 위한 권한을 부여합니다.
run: chmod +x backend/gradlew

- name: 🦉 gradle build 중입니다.
run: |
cd backend
./gradlew build -x test --stacktrace
- name: 🦉 Docker Hub에 로그인 후, docker image build 후 Docker Hub에 push합니다.
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}
run: |
cd backend
sudo docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
sudo docker build -t $DOCKERHUB_USERNAME/$DOCKERHUB_REPOSITORY:latest .
sudo docker push $DOCKERHUB_USERNAME/$DOCKERHUB_REPOSITORY:latest
63 changes: 63 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

frontend/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
115 changes: 115 additions & 0 deletions AI/price_prediction/SVM_LR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import pyupbit
import pandas as pd
import datetime
from sklearn.preprocessing import MinMaxScaler ,RobustScaler
import numpy as np
import math
import os
import tensorflow as tf
from sklearn.metrics import mean_squared_error

# API 키 설정 (보안 주의)
access_key = "3rCnY46Xw4Mx9q2tVrWGpzUPBtAjim82ZMn508Bd"
secret_key = "R1t5gFoPNZNTXaBlWHbdx85hPPvdhvSSZx2Y9uA7"

# 데이터 수집 기간 설정
start_date = datetime.datetime(2018, 1, 1)
time_now = datetime.datetime.now()
days_count = (time_now - start_date).days

# 업비트에서 데이터 수집
df = pyupbit.get_ohlcv("KRW-BTC", interval='day', count=days_count)

# 날짜를 열로 변환하고 필요한 열만 유지
df['date'] = df.index.strftime('%Y-%m-%d')
df = df[['date', 'close', 'volume']]

# 데이터 스케일링
scaler = MinMaxScaler()
# scaler = RobustScaler()
df[['close', 'volume']] = scaler.fit_transform(df[['close', 'volume']])
# print("data_scaling 결과")
# print(df.head())


# 데이터셋 함수 정의
def Dataset(Data, split_ratio):
total_rows = len(Data)
train_end_idx = int(total_rows * split_ratio)

Data['date'] = pd.to_datetime(Data['date'])

Train_Data = Data[['close', 'volume']].iloc[:train_end_idx].to_numpy()
Test_Data = Data[['close', 'volume']].iloc[train_end_idx:].to_numpy()

Data_Train = []
for i in range(0, len(Train_Data) - 4, 5):
Data_Train.append(Train_Data[i:i + 5])
Data_Train_X = np.array(Data_Train[:-1]).reshape((-1, 5 * 2))
Data_Train_Y = np.array([sequence[:, 0] for sequence in Data_Train[1:]]).reshape(-1) # 1차원으로 변경

Data_Test = []
for i in range(0, len(Test_Data) - 4, 5):
Data_Test.append(Test_Data[i:i + 5])
Data_Test_X = np.array(Data_Test[:-1]).reshape((-1, 5 * 2))
Data_Test_Y = np.array([sequence[:, 0] for sequence in Data_Test[1:]]).reshape(-1) # 1차원으로 변경

return Data_Train_X, Data_Train_Y, Data_Test_X, Data_Test_Y


# 데이터셋을 train과 test로 분할
train_test_split_ratio = 0.9
train_x, train_y, test_x, test_y = Dataset(df, train_test_split_ratio)


############################## SVM 모델 정의 ###########################################
from sklearn.svm import SVR

from sklearn.svm import SVR

# SVM 모델 정의 및 훈련
svm_model = SVR(kernel='rbf', C=100, gamma=0.1, epsilon=0.1)
svm_model.fit(train_x, train_y)

# 예측 수행
svm_predictions = svm_model.predict(test_x)

# 스케일 원복
pred_df = pd.DataFrame(np.zeros((len(svm_predictions), 2)), columns=["close", "volume"])
pred_df['close'] = svm_predictions # 예측 결과를 설정
prediction_scaled = scaler.inverse_transform(pred_df)[:, 0]

############################# linear regression 모델 정의 ################################
from sklearn.linear_model import LinearRegression

# 선형 회귀 모델 정의 및 훈련
lr_model = LinearRegression()
lr_model.fit(train_x, train_y)

# 예측 수행
lr_predictions = lr_model.predict(test_x)

# 스케일 원복
pred_df['close'] = lr_predictions # 예측 결과를 설정
lr_prediction_scaled = scaler.inverse_transform(pred_df)[:, 0]

# 실제 값 스케일 원복
df_original = pyupbit.get_ohlcv("KRW-BTC", interval='day', count=days_count)
df_original['date'] = df_original.index.strftime('%Y-%m-%d')
actual_values = df_original['close'][df['date'] >= '2023-10-27'][:-6].to_numpy()

# SVM 예측 오차 계산
svm_actual_values = actual_values[:len(prediction_scaled)]
svm_mse = mean_squared_error(svm_actual_values, prediction_scaled)
svm_rmse = math.sqrt(svm_mse)
print(f"SVM Mean Squared Error: {svm_mse}")
print(f"SVM Root Mean Squared Error: {svm_rmse}")

# 선형 회귀 예측 오차 계산
lr_actual_values = actual_values[:len(lr_prediction_scaled)]
lr_mse = mean_squared_error(lr_actual_values, lr_prediction_scaled)
lr_rmse = math.sqrt(lr_mse)
print(f"Linear Regression Mean Squared Error: {lr_mse}")
print(f"Linear Regression Root Mean Squared Error: {lr_rmse}")


Loading

0 comments on commit 7e6d72a

Please sign in to comment.