데이터 크기에 따른 k-NN의 예측력 연구: 삼성전자주가를 사례로 The Effect of Data Size on the k-NN Predictability: Application to Samsung Electronics Stock Market Prediction원문보기
본 논문은 학습데이터의 크기에 따른 사례기반추론기법이 주가예측력에 어떻게 영향을 미치는지 살펴본다. 삼성전자 주가를 대상을 학습데이터를 2000년부터 2017년까지 이용한 경우와 2015년부터 2017년까지 이용한 경우를 비교하였다. 테스트데이터는 두 경우 모두 2018년 1월 1일부터 2018년 8월 31일까지 이용하였다. 시계 열데이터의 경우 과거데이터가 얼마나 유용한지 살펴보는 측면과 유사사례개수의 중요성을 살펴보는 측면에서 연구를 진행하였다. 실험결과 학습데이터가 많은 경우가 그렇지 않은 경우보다 예측력이 높았다. MAPE을 기준으로 비교할 때, 학습데이터가 적은 경우, 유사사례 개수와 상관없이 k-NN이 랜덤워크모델에 비해 좋은 결과를 보여주지 못했다. 그러나 학습데이터가 많은 경우, 일반적으로 k-NN의 예측력이 랜덤워크모델에 비해 좋은 결과를 보여주었다. k-NN을 비롯한 다른 데이터마이닝 방법론들이 주가 예측력 제고를 위해 학습데이터의 크기를 증가시키는 것 이외에, 거시경제변수를 고려한 기간유사사례를 찾아 적용하는 것을 제안한다.
본 논문은 학습데이터의 크기에 따른 사례기반추론기법이 주가예측력에 어떻게 영향을 미치는지 살펴본다. 삼성전자 주가를 대상을 학습데이터를 2000년부터 2017년까지 이용한 경우와 2015년부터 2017년까지 이용한 경우를 비교하였다. 테스트데이터는 두 경우 모두 2018년 1월 1일부터 2018년 8월 31일까지 이용하였다. 시계 열데이터의 경우 과거데이터가 얼마나 유용한지 살펴보는 측면과 유사사례개수의 중요성을 살펴보는 측면에서 연구를 진행하였다. 실험결과 학습데이터가 많은 경우가 그렇지 않은 경우보다 예측력이 높았다. MAPE을 기준으로 비교할 때, 학습데이터가 적은 경우, 유사사례 개수와 상관없이 k-NN이 랜덤워크모델에 비해 좋은 결과를 보여주지 못했다. 그러나 학습데이터가 많은 경우, 일반적으로 k-NN의 예측력이 랜덤워크모델에 비해 좋은 결과를 보여주었다. k-NN을 비롯한 다른 데이터마이닝 방법론들이 주가 예측력 제고를 위해 학습데이터의 크기를 증가시키는 것 이외에, 거시경제변수를 고려한 기간유사사례를 찾아 적용하는 것을 제안한다.
Statistical methods such as moving averages, Kalman filtering, exponential smoothing, regression analysis, and ARIMA (autoregressive integrated moving average) have been used for stock market predictions. However, these statistical methods have not produced superior performances. In recent years, ma...
Statistical methods such as moving averages, Kalman filtering, exponential smoothing, regression analysis, and ARIMA (autoregressive integrated moving average) have been used for stock market predictions. However, these statistical methods have not produced superior performances. In recent years, machine learning techniques have been widely used in stock market predictions, including artificial neural network, SVM, and genetic algorithm. In particular, a case-based reasoning method, known as k-nearest neighbor is also widely used for stock price prediction. Case based reasoning retrieves several similar cases from previous cases when a new problem occurs, and combines the class labels of similar cases to create a classification for the new problem. However, case based reasoning has some problems. First, case based reasoning has a tendency to search for a fixed number of neighbors in the observation space and always selects the same number of neighbors rather than the best similar neighbors for the target case. So, case based reasoning may have to take into account more cases even when there are fewer cases applicable depending on the subject. Second, case based reasoning may select neighbors that are far away from the target case. Thus, case based reasoning does not guarantee an optimal pseudo-neighborhood for various target cases, and the predictability can be degraded due to a deviation from the desired similar neighbor. This paper examines how the size of learning data affects stock price predictability through k-nearest neighbor and compares the predictability of k-nearest neighbor with the random walk model according to the size of the learning data and the number of neighbors. In this study, Samsung electronics stock prices were predicted by dividing the learning dataset into two types. For the prediction of next day's closing price, we used four variables: opening value, daily high, daily low, and daily close. In the first experiment, data from January 1, 2000 to December 31, 2017 were used for the learning process. In the second experiment, data from January 1, 2015 to December 31, 2017 were used for the learning process. The test data is from January 1, 2018 to August 31, 2018 for both experiments. We compared the performance of k-NN with the random walk model using the two learning dataset. The mean absolute percentage error (MAPE) was 1.3497 for the random walk model and 1.3570 for the k-NN for the first experiment when the learning data was small. However, the mean absolute percentage error (MAPE) for the random walk model was 1.3497 and the k-NN was 1.2928 for the second experiment when the learning data was large. These results show that the prediction power when more learning data are used is higher than when less learning data are used. Also, this paper shows that k-NN generally produces a better predictive power than random walk model for larger learning datasets and does not when the learning dataset is relatively small. Future studies need to consider macroeconomic variables related to stock price forecasting including opening price, low price, high price, and closing price. Also, to produce better results, it is recommended that the k-nearest neighbor needs to find nearest neighbors using the second step filtering method considering fundamental economic variables as well as a sufficient amount of learning data.
Statistical methods such as moving averages, Kalman filtering, exponential smoothing, regression analysis, and ARIMA (autoregressive integrated moving average) have been used for stock market predictions. However, these statistical methods have not produced superior performances. In recent years, machine learning techniques have been widely used in stock market predictions, including artificial neural network, SVM, and genetic algorithm. In particular, a case-based reasoning method, known as k-nearest neighbor is also widely used for stock price prediction. Case based reasoning retrieves several similar cases from previous cases when a new problem occurs, and combines the class labels of similar cases to create a classification for the new problem. However, case based reasoning has some problems. First, case based reasoning has a tendency to search for a fixed number of neighbors in the observation space and always selects the same number of neighbors rather than the best similar neighbors for the target case. So, case based reasoning may have to take into account more cases even when there are fewer cases applicable depending on the subject. Second, case based reasoning may select neighbors that are far away from the target case. Thus, case based reasoning does not guarantee an optimal pseudo-neighborhood for various target cases, and the predictability can be degraded due to a deviation from the desired similar neighbor. This paper examines how the size of learning data affects stock price predictability through k-nearest neighbor and compares the predictability of k-nearest neighbor with the random walk model according to the size of the learning data and the number of neighbors. In this study, Samsung electronics stock prices were predicted by dividing the learning dataset into two types. For the prediction of next day's closing price, we used four variables: opening value, daily high, daily low, and daily close. In the first experiment, data from January 1, 2000 to December 31, 2017 were used for the learning process. In the second experiment, data from January 1, 2015 to December 31, 2017 were used for the learning process. The test data is from January 1, 2018 to August 31, 2018 for both experiments. We compared the performance of k-NN with the random walk model using the two learning dataset. The mean absolute percentage error (MAPE) was 1.3497 for the random walk model and 1.3570 for the k-NN for the first experiment when the learning data was small. However, the mean absolute percentage error (MAPE) for the random walk model was 1.3497 and the k-NN was 1.2928 for the second experiment when the learning data was large. These results show that the prediction power when more learning data are used is higher than when less learning data are used. Also, this paper shows that k-NN generally produces a better predictive power than random walk model for larger learning datasets and does not when the learning dataset is relatively small. Future studies need to consider macroeconomic variables related to stock price forecasting including opening price, low price, high price, and closing price. Also, to produce better results, it is recommended that the k-nearest neighbor needs to find nearest neighbors using the second step filtering method considering fundamental economic variables as well as a sufficient amount of learning data.
* AI 자동 식별 결과로 적합하지 않은 문장이 있을 수 있으니, 이용에 유의하시기 바랍니다.
문제 정의
일반적으로 학습데이터가 많으면 예측력이 높아질 것으로 생각할 수 있지만, 시계열 데이터의 경우 너무 오래된 데이터는 오히려 예측력에 부정적 영향을 줄 수도 있고, 학습데이터가 많으면 학습시간이 많이 걸리는 단점도 있을 수 있다. 또한 유사사례가 많을수록 반드시 예측력이 좋아진다고 볼 수 없기 때문에 본 연구에서는 학습데이터의 크기와 유사사례의 수에 따라서 예측력이 어떻게 달라지는지 랜덤워크 모델과 비교하였고, 실제 파이썬 소스코드를 설명하면서 독자들이 구현해볼 수 있도록 하였다.
본 논문은 학습데이터의 크기가 주가예측력에 어떻게 영향을 미치는지 k-NN을 통해서 살펴본다. 일반적으로 학습데이터가 많으면 예측력이 높아질 것으로 생각할 수 있지만, 시계열 데이터의 경우 너무 오래된 데이터는 오히려 예측력에 부정적 영향을 줄 수도 있고, 학습데이터가 많으면 학습시간이 많이 걸리는 단점도 있을 수 있다.
본 논문은 학습데이터의 크기에 따른 사례기반추론기법이 주가예측력에 어떻게 영향을 미치는지 살펴보았다. 삼성전자의 주가를 대상으로 학습데이터를 2000년부터 시작한 경우와 2015년부터 시작한 경우를 비교하였다.
본 연구에서는 학습데이터의 크기에 따라 예측결과가 어떻게 달라지는지 시계열데이터에 적용하여 살펴보았다. 실험결과에서 알 수 있듯이 일반적인 데이터마이닝 방법론이 랜덤워크(Random walk)모델보다 예측력을 높이는데 상당한 어려움이 있기에 이를 정교하게 개발할 필요가 있다는 것을 보여주었다.
비교를 위해서 사용되는 테스트데이터는 모두 2018년 1월부터 8월까지의 삼성전자 주가를 대상으로 하였다. 시계열 데이터의 경우 과거데이터가 얼마나 유용한지 살펴보고, 유사사례 개수의 중요성도 살펴보고자 했다.
가설 설정
k-최근접 이웃 알고리즘(k-NN)은 기본적으로 사례 기반 추론(Case-based Reasoning, CBR)이라 생각하면 된다. k-NN은 현재의 문제를 해결하기 위해, 과거의 유사한 문제에 해결책이 있다고 가정한다.
첫째, 명시적인 도메인 지식 모델을 필요로 하지 않는다.
제안 방법
[Table 2]는 학습데이터가 많은 경우, 예측결과를 보여주고 있다. MAPE을 기준으로 유사사례 개수가 5, 10, 15, 20, 30, 50, 100인 경우 랜덤워크모델과 비교하였다. 학습데이터가 많은 경우(large dataset), 랜덤워크모델의 경우 1.
둘째, 문제해결을 위해 사례를 재사용한다.
본 논문은 학습데이터의 크기에 따른 사례기반추론기법이 주가예측력에 어떻게 영향을 미치는지 살펴보았다. 삼성전자의 주가를 대상으로 학습데이터를 2000년부터 시작한 경우와 2015년부터 시작한 경우를 비교하였다. 비교를 위해서 사용되는 테스트데이터는 모두 2018년 1월부터 8월까지의 삼성전자 주가를 대상으로 하였다.
셋째, 필요시 제안한 방법도 수정한다.
k-Nearest neighbor를 구현한 함수를 소개한다. 첫째, 유사사례를 찾고, 둘째, 찾은 유사사례를 통해 각 유사사례에 대한 가중치를 적용하고, 마지막으로 가중치를 통해서 t+1시점의 삼성전자 종가를 예측한다. 이의 절차를 아래와 같이 단계별로 요약한다.
아래는 관련 코드를 보여준다. 학습데이터와 테스트데이터간의 거리를 구하고, 이를 distances 변수에 저장한 후 sort함수를 통해 거리 순서대로 저장한다.
대상 데이터
본 연구를 위해서 야후 파이낸스(finance.yahoo.com)에서 삼성전자 주가 데이터를 다운로드 받았다. 주가를 예측하기 위해 사용된 변수는 다음과 같다.
삼성전자의 주가를 대상으로 학습데이터를 2000년부터 시작한 경우와 2015년부터 시작한 경우를 비교하였다. 비교를 위해서 사용되는 테스트데이터는 모두 2018년 1월부터 8월까지의 삼성전자 주가를 대상으로 하였다. 시계열 데이터의 경우 과거데이터가 얼마나 유용한지 살펴보고, 유사사례 개수의 중요성도 살펴보고자 했다.
이 4가지 변수를 이용하여 그 다음날(t+1시점의) 주가를 예측했다. 실험에서는 두 가지 유형으로 학습데이터를 구분하여 사용했다. 첫째, 2000년 1월 1일부터 2017년 12월 31일까지의 학습데이터(총 4542개), 둘째, 2015년 1월 1일부터 2017년 12월 31일까지의 두 가지 유형의 학습데이터이다.
실험에서는 두 가지 유형으로 학습데이터를 구분하여 사용했다. 첫째, 2000년 1월 1일부터 2017년 12월 31일까지의 학습데이터(총 4542개), 둘째, 2015년 1월 1일부터 2017년 12월 31일까지의 두 가지 유형의 학습데이터이다. 테스트데이터의 경우, 두 가지 실험 모두 2018년 1월 1일부터 2018년 8월 31일까지 총 165개를 이용하였다.
첫째, 2000년 1월 1일부터 2017년 12월 31일까지의 학습데이터(총 4542개), 둘째, 2015년 1월 1일부터 2017년 12월 31일까지의 두 가지 유형의 학습데이터이다. 테스트데이터의 경우, 두 가지 실험 모두 2018년 1월 1일부터 2018년 8월 31일까지 총 165개를 이용하였다. <그림 1>은 테스트기간의 삼성전자 주가데이터를 보여주고 있다.
데이터처리
이상의 절차로 두 가지 학습데이터를 이용하여 예측한 결과를 랜덤워크모델과 비교하였다. 여기서 랜덤워크모델은 t+1시점의 종가 예측을 t시점의 종가로 예측하는 모델을 의미한다.
성능/효과
넷째, CBR은 새로운 사례를 학습하여 결과적으로 지식학습을 쉽게 한다.
둘째, CBR은 다양한 응용 분야에서 중요한 특징을 확인할 수 있게 한다.
셋째, 대용량의 과거 사례를 데이터베이스 기술을 통해서 효율적으로 저장하고 관리할 수 있다.
본 연구에서는 학습데이터의 크기에 따라 예측결과가 어떻게 달라지는지 시계열데이터에 적용하여 살펴보았다. 실험결과에서 알 수 있듯이 일반적인 데이터마이닝 방법론이 랜덤워크(Random walk)모델보다 예측력을 높이는데 상당한 어려움이 있기에 이를 정교하게 개발할 필요가 있다는 것을 보여주었다. 이는 단순한 주가데이터만으로 부족하기 때문에 관련된 많은 정보가 필요하다는 것을 시사한다.
후속연구
유사사례의 수에 대하여는 최적유사사례에 대하여 충분히 고려할 필요가 있음을 확인하였으며, 이는 향후 테스트기간에 따라서 최적유사사례를 변동하여 적용하는 방안도 고려해볼 수 있다. 또한 본 연구가 사례기반추론방법에만 적용한 것도 한계점이다.
예를 들어 특정기간동안의 거시경제변수도 반영해야할 필요가 있다. 또한 향후 기술적 지표들과 경제적 지표들의 조합을 반영한 모델의 발굴도 필요하다.
실험결과 예상한 바와 같이 학습데이터가 많은 경우가 그렇지 않은 경우보다 예측력이 높았다. 유사사례의 수에 대하여는 최적유사사례에 대하여 충분히 고려할 필요가 있음을 확인하였으며, 이는 향후 테스트기간에 따라서 최적유사사례를 변동하여 적용하는 방안도 고려해볼 수 있다. 또한 본 연구가 사례기반추론방법에만 적용한 것도 한계점이다.
향후 시가, 저가, 고가, 거래량, 종가외의 주가예측과 관련된 거시경제 변수들도 고려해 볼 수 있고, 거시경제변수를 고려한 해당 기간에서의 유사사례를 추출하여 적용하는 방법도 고려할 수 있다. 또한 해당 시계열자료를 묶어, 이를 사례로 생각하여 모델에 반영하는 상황벡터(context vector)를 고려하는 것도 필요하다.
질의응답
핵심어
질문
논문에서 추출한 답변
사례기반추론이란 무엇인가?
사례기반추론은 이전의 유사한 상황을 기억하고 그 상황에 대한 정보와 지식을 재사용함으로써 새로운 문제를 해결하기 위한 접근법이다(Aamodt and Plaza, 1994). CBR은 다음의 4개의 단계를 거친다.
머신러닝기법 이외의 주식시장예측을 위한 통계적 방법에는 무엇이 있는가?
주식시장예측을 위한 통계적 방법으로는 가중이동평균(moving average), 칼만필터링(Kalman filtering), 지수평활법(exponential smoothing), 회귀분석(regression analysis), ARIMA(autoregressive integrated moving average)모형 등이 사용되고 있다. 그러나 이러한 통계적 방법론들은 일반적으로 예측률이 높지 않아 최근에는 머신러닝기법들이 실제로 많이 이용되고 있다.
CBR의 장점은?
첫째, 명시적인 도메인 지식 모델을 필요로 하지 않는다.
둘째, CBR은 다양한 응용 분야에서 중요한 특징을 확인할 수 있게 한다.
셋째, 대용량의 과거 사례를 데이터베이스 기술을 통해서 효율적으로 저장하고 관리할 수 있다.
넷째, CBR은 새로운 사례를 학습하여 결과적으로 지식학습을 쉽게 한다.
※ AI-Helper는 부적절한 답변을 할 수 있습니다.