刚学python小白的疑惑
import talib
from jqdata import *
test_stock="600600.XSHG"
start_date= datetime.date(2012,1,4)
end_date= datetime.date(2019,1,2)
trading_days= list(get_all_trade_days())
start_date_index=trading_days.index(start_date)
end_date_index=trading_days.index(end_date)
x_all=[]
y_all=[]
for index in range(start_date_index,end_date_index): start_day=trading_days[index-30] end_day=trading_days[index] stock_data=get_price(test_stock,start_date=start_day,end_date=end_day,frequency="daily",fields=["close"]) close_prices=stock_data["close"].values ma_data=talib.MA(close_prices)[-2] rsi_data=talib.RSI(close_prices)[-2] mom_data=talib.MOM(close_prices)[-2] features=[] features.append(ma_data) features.append(rsi_data) features.append(mom_data) label=False
if close_prices[-1]>close_prices[-2]: label=True
x_all.append(features) y_all.append(label)
x_train=x_all[: -1]
y_train=y_all[: -1]
x_test=x_all[-1]y_test=y_all[-1]print("数据已准备好了")
from sklearn.ensemble import RandomForestClassifier
clf=RandomForestClassifier()
clf.fit(x_train,y_train)
prediction = clf.predict(x_test)
if prediction==y_test :
print("预测正确")
else:
print("预测错误")
现在就是出错的提示,因为我是头条新手,排版很乱,不能按原来的格式
ValueError Traceback (most recent call last) in 5 clf.fit(x_train,y_train) 6 ----> 7 prediction = clf.predict(x_test) 8 9 if prediction==y_test :/opt/conda/lib/python3.6/site-packages/sklearn/ensemble/forest.py in predict(self, X) 536 The predicted classes. 537 """--> 538 proba = self.predict_proba(X) 539 540 if self.n_outputs_ == 1:/opt/conda/lib/python3.6/site-packages/sklearn/ensemble/forest.py in predict_proba(self, X) 576 check_is_fitted(self, "estimators_") 577 # Check data--> 578 X = self._validate_X_predict(X) 579 580 # Assign chunk of trees to jobs/opt/conda/lib/python3.6/site-packages/sklearn/ensemble/forest.py in _validate_X_predict(self, X) 355 "call `fit` before exploiting the model.") 356 --> 357 return self.estimators_[0]._validate_X_predict(X, check_input=True) 358 359 @property/opt/conda/lib/python3.6/site-packages/sklearn/tree/tree.py in _validate_X_predict(self, X, check_input) 371 """Validate X whenever one tries to predict, apply, predict_proba""" 372 if check_input:--> 373 X = check_array(X, dtype=DTYPE, accept_sparse="csr") 374 if issparse(X) and (X.indices.dtype != np.intc or 375 X.indptr.dtype != np.intc):/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator) 439 "Reshape your data either using array.reshape(-1, 1) if " 440 "your data has a single feature or array.reshape(1, -1) "--> 441 "if it contains a single sample.".format(array)) 442 array = np.atleast_2d(array) 443 # To ensure that array flags are maintainedValueError: Expected 2D array, got 1D array instead:array=[32.133 54.359715 -0.56].Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
这个是再joinquant的预测股价的随机森林的应用代码,我就想学习下,发现运行的时候就出错了,请问错在哪里
新年新机,性能之王!00X00序言随着数码科技的迅猛发展,数码用户越来越习惯使用轻便易用的移动互联网设备来上网和娱乐,平板产业同样经历着巨大变更,2017年又是新概念平板与PC合二为一高性能低能耗生活
中秋邀君共赏新机Tbook16S畅玩剑侠情缘。明月几时有,抬头自己瞅!平板数码产品一波还未平息,一波又侵袭,2016年又引来一次产品理念变革,PC平板二合一的潮流设计,揭开国内平板市场新序幕,自年初台电在召开Tbook发布会至
华为石墨烯电池已经商用为什么遭到中科院清华院的质疑?在2016年12月的第一天,华为在中央研究院瓦特实验室在日本大会上宣布锂电池领域有重大突破,推出世界首个高温寿命石墨烯基锂离子电池。报告中明确指出,主要针对温度做出了明确的解释,在
360巴迪龙儿童手表发布后短短1个月,超越同行勇夺销量第一。360巴迪龙儿童手表发布后短短1个月,超越同行勇夺销量第一,凭的是什么?导读近年些来,社交软件的迅速发展和网络应用的普及,儿童走失被拐的事件得到了越来越多的报道,类似的新闻更是已经
酷比魔方iwork1X刷机Remix2。0系统分享PConline资讯新机油不知道如何刷机,或者刷机遇到问题,主要是没认真参考刷机教程,这里我把经常会遇到的问题,归纳下另外刷机会把平板数据清空,若有重要资料提前做好备份。本次提供I
电芯强劲,高效转化,物色移动电源匠心之作随着移动电源越来越走进生活,越来越普及,如何选择一款适合自己的数码产品,它的必需性能强电能大,同时外形时尚美观,又可以携带方便的移动电源,那么请大家关注这款酷比魔方的新品M2000
2016一款大家都会喜欢的超级平板序酷比魔方作为国内知名平板厂家,一直致力于为用户打造更加优秀的使用体验,在业界同类产品中,不但性价比突出,同时工艺卓越独具匠心,这款美的搭载Skylake芯64GB内存,将给您带来
炫酷极品!青春活力自我的台电T9系列移动电源评测T9移动电源(三种款式)凭外观欣赏,都非常青春时尚,充满活力激情,自我奔放德国设计师设计,产品电芯强劲,聚合物锂电池安全稳定外形超薄,携带方便双USB,2。1A输入可广泛应用于手机
Thinker笔记本低调入市,掀起性价风波,各位老板怎么看不光是联想也不是小米,thinker笔记本低调入市,却掀起新一轮性价风波,各位老板怎么看?3月30日,国内著名平板电脑厂商酷比魔方联合微软和英特尔在京召开发布会,期间酷比魔方发布了
USB3。1移动硬盘盒速度真快!大家好!我是蛮牛士,本次向大家分享一款由深圳市元创时代科技有限公司原创设计的ORICOTypeC高速移动硬盘盒子,说起ORICO应该家喻户晓了,短短几年内已经成为国内著名的数码周边
安卓桌面级应用,REMIXMINI小盒子RemixMini。jpg(1。19MB,下载次数0)下载附件201511291349上传小伙伴们烧机友们大家好!本次向大家分享技德科技2015年度主打产品之一RemixMini,