源码第64行是:model = svr.fit(X, Y)
我在后面加上:
import scipy.stats as stats
corr, p = stats.pearsonr(Y, svr.predict(X))
结果发生错误:
Traceback (most recent call last):
File "/tmp/jqcore/jqboson/jqboson/core/entry.py", line 368, in _run
engine.start()
File "/tmp/jqcore/jqboson/jqboson/core/engine.py", line 232, in start
self._dispatcher.start()
File "/tmp/jqcore/jqboson/jqboson/core/dispatcher.py", line 273, in start
self._run_loop()
File "/tmp/jqcore/jqboson/jqboson/core/dispatcher.py", line 240, in _run_loop
self._loop.run()
File "/tmp/jqcore/jqboson/jqboson/core/loop/loop.py", line 84, in run
self._handle_queue()
File "/tmp/jqcore/jqboson/jqboson/core/loop/loop.py", line 124, in _handle_queue
message.callback(message.callback_data)
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_subscriber.py", line 221, in broadcast
consumer.send(market_data)
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_consumer_manager.py", line 59, in consumer_gen
msg_callback()
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_consumer_manager.py", line 52, in msg_callback
callback(market_data)
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_consumer_manager.py", line 122, in wrapper
result = callback(*args, kwargs)
File "/tmp/jqcore/jqboson/jqboson/core/strategy.py", line 428, in wrapper
return callback(ucontext)
File "/tmp/strategy/user_code.py", line 65, in trade
corr, p = stats.pearsonr(Y, svr.predict(X))
File "scipy/stats/stats.py", line 2546, in pearsonr
r = max(min(r, 1.0), -1.0)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
是因为Y不止一列变量吗?我应该如何求得这个相关系数呢?
源码第55-59行是:
X = df[['log_NC', 'LEV', 'NI_p', 'NI_n', 'g', 'log_RD','801010', '801020', '801030', '801040', '801050',
'801080', '801110', '801120', '801130', '801140', '801150', '801160', '801170', '801180', '801200',
'801210', '801230', '801710', '801720', '801730', '801740', '801750', '801760', '801770', '801780',
'801790', '801880', '801890']]
注意到了,df后面是两重中括号的。
现在想从每4条记录中抽一条记录出来,
在后面加上:
test = X[X.index%4==0]
结果报错:
Traceback (most recent call last):
File "/tmp/jqcore/jqboson/jqboson/core/entry.py", line 368, in _run
engine.start()
File "/tmp/jqcore/jqboson/jqboson/core/engine.py", line 232, in start
self._dispatcher.start()
File "/tmp/jqcore/jqboson/jqboson/core/dispatcher.py", line 273, in start
self._run_loop()
File "/tmp/jqcore/jqboson/jqboson/core/dispatcher.py", line 240, in _run_loop
self._loop.run()
File "/tmp/jqcore/jqboson/jqboson/core/loop/loop.py", line 84, in run
self._handle_queue()
File "/tmp/jqcore/jqboson/jqboson/core/loop/loop.py", line 124, in _handle_queue
message.callback(message.callback_data)
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_subscriber.py", line 221, in broadcast
consumer.send(market_data)
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_consumer_manager.py", line 59, in consumer_gen
msg_callback()
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_consumer_manager.py", line 52, in msg_callback
callback(market_data)
File "/tmp/jqcore/jqboson/jqboson/core/mds/market_data_consumer_manager.py", line 122, in wrapper
result = callback(*args, kwargs)
File "/tmp/jqcore/jqboson/jqboson/core/strategy.py", line 428, in wrapper
return callback(ucontext)
File "/tmp/strategy/user_code.py", line 64, in trade
test = X[X.index%4==0]
TypeError: unsupported operand type(s) for %: 'Index' and 'int'
请问用什么办法才能从这个df或者X中抽取记录呢?