2016-06-30 6 views

答えて

1

をあなたは時系列であるベクトルを必要とする時系列を分割するには:私は、Rは、結果コマンド
splits (APILts, c(rep("train", 8483), "test")) を入力してください。に割り当てられている

data(AirPassengers) 

データ:

Error: is.timeSeries(x) is not TRUE 
ここ

TSオブジェクトと時系列を分割する方法の例:

エラーがAPILtsは、TSオブジェクトではないことを示唆しています便利なベクトル

これは毎回コードを変更しないようにする簡単な方法です。

series <- AirPassengers 

プロットシリーズ

plot(series, col="darkblue", ylab="Passegners on airplanes") 

プロットシリーズ

windows(width=800,height=350) # set the window with the dimensions you need 

boxplot(split(series, cycle(series)), names = month.abb, col = "gold") 

テストセットのサイズの季節的分布は、我々は、

だから、総サンプルの典型的には約40%ですトレーニングセットでシリーズを分割し、テストが

# Training set 
# Use data from 1949 to 1955 for forecasting 

sr = window(series, start=1949, end=c(1955,12)) 

# Test set 
# Use remaining data from 1956 to 1960 to test accuracy 

ser = window(series, start=1956, end=c(1960,12)) 
を設定します

これで準備は整いました。

# In this example, the data you want to convert into a ts object are in the first column 

series <- ts(dat[[1]], frequency = 12, start = c(1969, 1)) 
:時系列

# Data 

dat <- c(27, 28, 25, 22, 19, 21, 24, 24, 22, 16, 27, 41, 29, 24, 15, 27, 25, 21, 15, 41, 19, 24, 34, 20, 25, 34, 31, 29, 38, 36, 27, 37, 31, 28, 25, 34, 40, 36, 39, 19, 40, 31, 29, 39, 29, 40, 34, 31) 


# Convert the data to time series 

series <- ts(dat, frequency = 12, start = c(1969, 1)) 

# Inspect the series 

series 

plot(series) 

あなたがデータフレームとしてデータをアップロードした場合はいつか、あなたは正確に列を指定する必要がありますにデータを変換するには

関連する問題