LSTM to forecast numerical data by having categorical data as input

别来无恙 提交于 2021-02-11 12:50:53

问题


I have a similar DataFrame:

df = pd.DataFrame([
{'date':'2021-01-15', 'value':145, 'label':'negative'},
{'date':'2021-01-16', 'value':144, 'label':'positive'},
{'date':'2021-01-17', 'value':147, 'label':'positive'},
{'date':'2021-01-18', 'value':146, 'label':'negative'},
{'date':'2021-01-19', 'value':155, 'label':'negative'},
{'date':'2021-01-20', 'value':157, 'label':'positive'},
{'date':'2021-01-21', 'value':158, 'label':'positive'},
{'date':'2021-01-22', 'value':157, 'label':'negative'},
{'date':'2021-01-23', 'value':157, 'label':'positive'},
{'date':'2021-01-24', 'value':152, 'label':'positive'}, 
{'date':'2021-01-25', 'value':159, 'label':'negative'},
{'date':'2021-01-26', 'value':162, 'label':'positive'},
{'date':'2021-01-27', 'value':160, 'label':'positive'},
{'date':'2021-01-28', 'value':153, 'label':'negative'},
{'date':'2021-01-29', 'value':149, 'label':'negative'},
{'date':'2021-01-30', 'value':156, 'label':'positive'},
{'date':'2021-01-31', 'value':168, 'label':'positive'},
{'date':'2021-02-01', 'value':179, 'label':'negative'},
{'date':'2021-02-02', 'value':184, 'label':'positive'},
{'date':'2021-02-03', 'value':189, 'label':'positive'},
{'date':'2021-02-04', 'value':196, 'label':'positive'}])

I have already converted date column strings into datetime format and set it as index with set_index method.

Once n and m are fixed, I would like to use a Recurrent Neural Network (LSTM) to predict last n values of the value column by taking into account the categories of the label column only.

I have just encoded label column features with the following:

from sklearn.preprocessing import OneHotEncoder
hot = OneHotEncoder(sparse = False).fit_transform(df.label.to_numpy().reshape(-1, 1))

and scaled data:

from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler(feature_range = (0, 1))
scaled = scaler.fit_transform(df.value.values)

but I cannot succeed in taking into account m and n conditions to build train and test set.

Any suggestions?


回答1:


First of all, you have to transform the dataset into a time-series form that supported by LSTM. build a model to predict the next day only and roll the testing process as the number of predictions you want from a single prediction.
you can get complete from here



来源:https://stackoverflow.com/questions/66045592/lstm-to-forecast-numerical-data-by-having-categorical-data-as-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!