2016-07-12 2 views
1
myformula <- close ~ High+Low+Open 
nn_close <- neuralnet(myformula,data=train_,hidden=c(5,3),linear.output=T) 
nn_close$net.result[[1]] 

안녕하세요. 나는 가까운 가격을 예측하기 위해 사용할 신경망 모델을 구축했다. 누군가가 nn_close$net.result[[1]] 라인이하는 것을 나에게 설명해 줄 수 있습니까? 내가 CRAN documentation을 체크 했는데도 아직 명확하지 않습니다.R 신경망 패키지 - net.result는 무엇을 보여줍니까?

답변

1

compute()$net.result의 결과는 하나의 레벨 만 포함하고 있으며 이것은 각 샘플이 주어진 종 (이 예에서는)이 될 확률을 나타냅니다. 즉, 행의 합은 (대략적으로) 1과 같습니다. 다음 예에서이 정보를 사용하여 데이터의 유효성을 검사하는 하위 집합의 종을 예측하고이를 table을 사용하여 실제 값과 비교합니다.

# install.packages("neuralnet") 
library(neuralnet) 

# adapted iris 
data(iris) 
iris2 <- iris 
iris2$setosa <- c(iris2$Species == 'setosa') 
iris2$versicolor <- c(iris2$Species == 'versicolor') 
iris2$virginica <- c(iris2$Species == 'virginica') 
# iris2$Species <- NULL 

# training and validation subsets 
train.samples <- sample(nrow(iris), nrow(iris)*0.5) 
train <- iris2[train.samples,] 
valid <- iris2[-train.samples,] 

# fit model 
inet <- neuralnet(setosa + versicolor + virginica ~ Sepal.Length + Sepal.Width + 
    Petal.Length + Petal.Width, train, hidden=3, lifesign="full") 

# prediction 
pred <- compute(inet, valid[,1:4]) 
head(pred$net.result) # only one level (probability of each category) 
predspp <- factor(c("setosa" , "versicolor", "virginica"))[apply(pred$net.result, MARGIN=1, FUN=which.max)] 
table(predspp, valid$Species) 
# predspp  setosa versicolor virginica 
# setosa   19   0   0 
# versicolor  0   24   4 
# virginica  0   2  26 

내 경우에는 모든 상처 샘플을 정확하게 예측했습니다. 각색 및 버지니아에 대해 각각 2 건 및 4 건의 잘못된 예측이있었습니다. 일반적으로 유효 샘플의 92 % (69/75 * 100)에 대한 예측은 정확했습니다.

1

당신이 더 나은 예와 이해 (나는 그것을 조금 수정하지만 난 here에서 그것을 가지고) :

head(predict$net.result) 
#    [,1]   [,2]   [,3] 
#80 0.0167232688257 0.995316738272 -0.011840391533 
#112 -0.0008289388986 -0.006814451178 1.007637170495 
#17 1.0028534166840 0.004240124926 -0.007115290101 
#104 -0.0002256650283 -0.031771967776 1.031855488316 
#149 0.0019424886784 0.007205356060 0.990892583485 
#82 -0.0061699713404 0.957656929739 0.048564910023 
head(inet$net.result[[1]]) 
#    [,1]   [,2]   [,3] 
#80 0.0167232688257 0.995316738272 -0.011840391533 
#112 -0.0008289388986 -0.006814451178 1.007637170495 
#17 1.0028534166840 0.004240124926 -0.007115290101 
#104 -0.0002256650283 -0.031771967776 1.031855488316 
#149 0.0019424886784 0.007205356060 0.990892583485 
#82 -0.0061699713404 0.957656929739 0.048564910023 

내가 사용 :

itrain <- iris[sample(1:150, 50),] 

itrain$setosa <- c(itrain$Species == 'setosa') 

itrain$versicolor <- c(itrain$Species == 'versicolor') 

itrain$virginica <- c(itrain$Species == 'virginica') 

itrain$Species <- NULL 

inet <- neuralnet(setosa + versicolor + virginica ~ Sepal.Length + Sepal.Width + 
        Petal.Length + Petal.Width, itrain, hidden=3, lifesign="full") 

#make a prediction on the training set and then compare to 
#inet$net.result[[1]] 
predict <- compute(inet, itrain[1:4]) 

이제 결과를 살펴 compute을 사용하여 신경망 모델을 사용하여 학습 집합에 대한 예측을 수행합니다.

표시되는대로 inet$net.result[[1]]predict$net.result은 같습니다. 따라서 inet$net.result[[1]]은 모델을 훈련하는 데 사용한 데이터 집합에 대한 예측 일뿐입니다 (lm 모델의 fitted.values와 동일 함).

@sebastianmm의 유용한 의견에 따르면 net.result이 목록입니다. 기본적으로 neuralnet에는 rep이라는 매개 변수가있어 하나의 호출에서 여러 모델을 학습 할 수 있습니다. rep이 1보다 큰 경우 net.result은 1보다 클 것입니다 (다른 구성 요소 (weights, result.matrix, start.weights)).

+0

대단히 고마워요. Inet $ net.result [[1]] 여기서 결과는 1 요소를 포함하는 목록입니다. 이것은 특정 시나리오에서 inet $ net.result [2]와 같이 결과 집합이 1 개 이상있을 수 있음을 나타 냅니까? – edb500

+0

@ edb500 매우 환영합니다. 솔직히 말해서'inet $ net.result [[2]] '또는 다른 요소를 사용한 적이 없으므로 확실하지 않습니다. – LyzandeR

+1

어쨌든 고맙습니다. – edb500