stock price prediction by using nnet

北慕城南 提交于 2019-12-02 16:31:55

问题


stock<-structure(list(week = c(1L, 2L, 5L, 2L, 3L, 4L, 3L, 2L, 1L, 5L, 
        1L, 3L, 2L, 4L, 3L, 4L, 2L, 3L, 1L, 4L, 3L), 
    close_price = c(774000L, 
        852000L, 906000L, 870000L, 1049000L, 941000L, 876000L, 874000L, 
        909000L, 966000L, 977000L, 950000L, 990000L, 948000L, 1079000L, 
        NA, 913000L, 932000L, 1020000L, 872000L, 916000L), 
    vol = c(669L, 
        872L, 3115L, 2693L, 575L, 619L, 646L, 1760L, 419L, 587L, 8922L, 
        366L, 764L, 6628L, 1116L, NA, 572L, 592L, 971L, 1181L, 1148L), 
    obv = c(1344430L, 1304600L, 1325188L, 1322764L, 1365797L, 
        1355525L, 1308385L, 1308738L, 1353999L, 1364475L, 1326557L, 
        1357572L, 1362492L, 1322403L, 1364273L, NA, 1354571L, 1354804L, 
        1363256L, 1315441L, 1327927L)), 
    .Names = c("week", "close_price", "vol", "obv"), 
    row.names = c(16L, 337L, 245L, 277L, 193L, 109L, 323L, 342L, 106L, 
        170L, 226L, 133L, 72L, 234L, 208L, 329L, 107L, 103L, 71L, 284L, 253L), 
    class = "data.frame")

I have data set like this form called Nam which has observations of 349 and I want to use nnet to predict close_price.

obs<- sample(1:21, 20*0.5, replace=F)
tr.Nam<- stock[obs,]; st.Nam<- stock[-obs,] 
# tr.Nam is a training data set while st.Nam is test data.

library(nnet)
Nam_nnet<-nnet(close_price~., data=tr.Nam, size=2, decay=5e-4)

By this statement, I think I made a certain function to predict close_price.

summary(Nam_nnet)
y<-tr.Nam$close_price
p<-predict(Nam_nnet, tr.Nam, type="raw") 

I expected p to be the predicted value of close_price, but it has only values of 1. Why doesn't p have the continuous value of close_price?

tt<-table(y,p)
summary(tt)
tt

回答1:


I think I could do a bit better with a reproducible example but I think the problem may be one (or more) of several reasons. Firstly, do a str(data) to make sure each variable is of the correct type (factor, numeric, etc.). Also, Neural Nets usually respond better to standardized, scaled, and centered data otherwise the inputs get oversaturated with larger numeric inputs which might be the case if the 'week' variable is numeric.

In summary, definitely check the types of each variable to make sure you are inputting the correct forms and consider scaling your data to be smooth and so the inputs are of comparable magnitudes.



来源:https://stackoverflow.com/questions/20846071/stock-price-prediction-by-using-nnet

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