当我使用print(xdata[0:1, 0:1, :])
运行代码时,我得到了第一行数组,但当我使用print(state)
运行代码时,我得到了一行数组,其中包含扩展数据,但我不知道为什么会得到它。你知道吗
def load_data(test=False):
#prices = pd.read_pickle('data/OILWTI_1day.pkl')
#prices = pd.read_pickle('data/EURUSD_1day.pkl')
#prices.rename(columns={'Value': 'close'}, inplace=True)
prices = pd.read_pickle('D:\data/XBTEUR_1day.pkl')
prices.rename(columns={'Open': 'open', 'High': 'high', 'Low': 'low', 'Close': 'close', 'Volume (BTC)': 'volume'}, inplace=True)
x_train = prices.iloc[-2000:-300,]
x_test= prices.iloc[-2000:,]
if test:
return x_test
else:
return x_train
def init_state(indata, test=False):
close = indata['close'].values
diff = np.diff(close)
diff = np.insert(diff, 0, 0)
sma15 = SMA(indata, timeperiod=15)
sma60 = SMA(indata, timeperiod=60)
rsi = RSI(indata, timeperiod=14)
atr = ATR(indata, timeperiod=14)
#--- Preprocess data
xdata = np.column_stack((close, diff, sma15, close-sma15, sma15-sma60, rsi, atr))
xdata = np.nan_to_num(xdata)
if test == False:
scaler = preprocessing.StandardScaler()
xdata = np.expand_dims(scaler.fit_transform(xdata), axis=1)
joblib.dump(scaler, 'D:\data/scaler.pkl')
elif test == True:
scaler = joblib.load('D:\data/scaler.pkl')
xdata = np.expand_dims(scaler.fit_transform(xdata), axis=1)
state = xdata[0:1, 0:1, :]
return state, xdata, close
indata = load_data(test=True)
A = init_state(indata, test=False)
print(xdata[0:1, 0:1, :])
您没有以合理的方式存储返回值。将这三个值都存储到
A
,然后访问xdata
。现在还不清楚为什么后者会在全球范围内被定义,如果是的话,那只是其他地方遗留下来的一些东西。使用state, xdata, close = init_state(...)
而不是A = ...
,一切都应该像execpected一样工作。你知道吗相关问题 更多 >
编程相关推荐