我正在玩Hidden Markov模型来解决股市预测问题.我的数据矩阵包含特定安全性的各种功能:
01-01-2001, .025, .012, .01
01-02-2001, -.005, -.023, .02
Run Code Online (Sandbox Code Playgroud)
我适合一个简单的GaussianHMM:
from hmmlearn import GaussianHMM
mdl = GaussianHMM(n_components=3,covariance_type='diag',n_iter=1000)
mdl.fit(train[:,1:])
Run Code Online (Sandbox Code Playgroud)
使用模型(λ),我可以解码观察向量以找到对应于观察向量的最可能的隐藏状态序列:
print mdl.decode(test[0:5,1:])
(72.75, array([2, 1, 2, 0, 0]))
Run Code Online (Sandbox Code Playgroud)
在上面,我已经解码了观察向量O t =(O 1,O 2,...,O d)的隐藏状态序列,其包含测试集中的前五个实例.我想估计测试集中第六个实例的隐藏状态.想法是迭代第六个实例的一组离散的可能特征值,并选择具有最高似然性的观测序列O t + 1 argmax = P(O 1,O 2,...,O d + 1 |λ ).一旦我们观察到O d + 1的真实特征值,我们就可以将序列(长度为5)移动一次并重新执行:
l = 5
for i in xrange(len(test)-l):
values = []
for a in arange(-0.05,0.05,.01):
for b in arange(-0.05,0.05,.01):
for c in arange(-0.05,0.05,.01):
values.append(mdl.decode(vstack((test[i:i+l,1:],array([a,b,c])))))
print …
Run Code Online (Sandbox Code Playgroud) python markov-chains markov-models hidden-markov-models hmmlearn
当我设置HADOOP_HOME =/cygdrive/c/ecosystem/hadoop-2.5.1然后尝试从Cygwin 运行bin/hadoop fs或bin/hadoop hadoop-streaming.jar时,我收到以下错误:
ERROR [main] util.Shell (Shell.java:getWinUtilsPath(373)) - Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:355)
at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:370)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:363)
at org.apache.hadoop.util.GenericOptionsParser.preProcessForWindows(GenericOptionsParser.java:432)
at org.apache.hadoop.util.GenericOptionsParser.parseGeneralOptions(GenericOptionsParser.java:478)
at org.apache.hadoop.util.GenericOptionsParser.<init>(GenericOptionsParser.java:170)
at org.apache.hadoop.util.GenericOptionsParser.<init>(GenericOptionsParser.java:153)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:64)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
at org.apache.hadoop.fs.FsShell.main(FsShell.java:340)
Exception in thread "main" java.lang.RuntimeException: core-site.xml not found
at org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:2269)
at org.apache.hadoop.conf.Configuration.loadResources(Configuration.java:2195)
at org.apache.hadoop.conf.Configuration.getProps(Configuration.java:2112)
at org.apache.hadoop.conf.Configuration.set(Configuration.java:989)
at org.apache.hadoop.conf.Configuration.set(Configuration.java:961)
at org.apache.hadoop.conf.Configuration.setBoolean(Configuration.java:1299)
at org.apache.hadoop.util.GenericOptionsParser.processGeneralOptions(GenericOptionsParser.java:319)
at …
Run Code Online (Sandbox Code Playgroud) 我有一个接受图片上传的表单:
<form name="upload" enctype="multipart/form-data" method="post" class="form-horizontal">
<div class="control-group">
<div class="span2">
<label for="image" class="control-label">Upload image:</label>
</div>
<div class="span10">
<input id="image" name="image" type="file" class="span7" accept="image/*"/>
</div>
</div>
<div class="form-group">
<div class="span2"></div>
<div class="span10">
<button class="btn btn-medium btn-primary" type="submit">Submit</button>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
当我request.vars['image']
,返回以下内容:
FieldStorage('image', 'a.png', '\x89PNG\r\n\x1a\n\x00...')
Run Code Online (Sandbox Code Playgroud)
我如何访问这些项目?如果我尝试使用它,就像我的dict一样,我收到一个错误,该对象不可索引.我以前从未使用过FieldStorage,所以我不确定我需要做什么来访问这些数据.