本文主要是介绍HMM隐马尔科夫模型与实例2: 预测股票走势,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
from __future__ import print_function #python2.X,使用print就得像python3.X那样加括号使用
import datetime
import numpy as np
import pandas as pd
from matplotlib import cm, pyplot as plt
import mpl_finance as mpf
from matplotlib.dates import YearLocator, MonthLocator
from hmmlearn.hmm import GaussianHMM
import mathstart_date = datetime.date(2012, 1, 1)
end_date = datetime.date.today() - datetime.timedelta(days = 15)data = pd.read_csv('data2.csv', header=0)
data['date'] = pd.to_datetime(data['date])
data.head()
data.reset_index(inplace=True, drop=False)
data.drop(['index','open','low','high','Adj Close'], axis=1, inplace=True)data['date'] = data['date'].apply(datetime.datetime.toordinal)
# date.toordinal(): 返回日期对应的 Gregorian Calendar 日期data.head()
- itertuples() 将DataFrame迭代为元祖
- numpy.diff() 沿着指定轴计算第N维的离散差值, 其实就是执行后一个元素减去前一个元素
df = list(data.itertuples(index=False, name=Name))
dates = np.array([x[0]
这篇关于HMM隐马尔科夫模型与实例2: 预测股票走势的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!