Created
December 13, 2015 01:05
-
-
Save stockedge/ae068fd378c941321b99 to your computer and use it in GitHub Desktop.
移動平均を使って予測してみる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> sum(diag(tbl)) / sum(tbl) | |
[1] 0.4991274 | |
>#予測力全く無し |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#moveingAverage from http://www.cookbook-r.com/Manipulating_data/Calculating_a_moving_average/ | |
close.ma <- movingAverage(diff(read.csv("C:\\usdjpy_d.csv")$Close), n=10) | |
data <- NULL | |
for (i in seq(1,(length(close.ma)-50),by=10)) { | |
data <- rbind(data, c(close.ma[i:(i+39)],Dir = close.ma[i+50])) | |
} | |
data <- as.data.frame(data) | |
data$Dir <- as.factor(data$Dir > 0) | |
library(randomForest) | |
train <- data[1:(nrow(data)/2),] | |
test <- data[(nrow(data)/2):nrow(data),] | |
model.rf <- randomForest(Dir~., train) | |
pred <- predict(model.rf, test) | |
tbl <- table(pred, test$Dir) | |
sum(diag(tbl)) / sum(tbl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment