我涉及示例中的最后一行。我想为每个$.getJSON('data.json', function(json) {
if(json[2].data){
for (i = 0; i < json[3].data.length; i++) {
choiceSelection[i] = new Array;
choiceSelection[i][0] = json[2].data[i].question;
choiceSelection[i][1] = json[2].data[i].correctChoice;
choiceSelection[i][2] = json[2].data[i].choice1;
choiceSelection[i][3] = json[2].data[i].choice2;
}
// choiceSelection.length = choiceSelection.length;
displayQuestion();
console.log(json[2]);
}
})
值建立一个[
{
"name": "match numbers 1",
"template": "matching",
"data": [
[
"six",
"Images/Number6.jpg"
],
[
"eight",
"Images/Number8.jpg"
],
[
"nine",
"Images/Number9.jpg"
]
]
},
{
"name": "order numbers 1",
"template": "ordering",
"data": [
[
"Images/Number6.jpg"
],
[
"Images/Number8.jpg"
],
[
"Images/Number9.jpg"
]
]
},
{
"name": "animal",
"template": "picture game",
"data": [
{
"question": "Where is the cat?",
"correctChoice": "Images/5cats.jpg",
"choice1": "Images/squirrel.png",
"choice2": "Images/beagle.png"
},
{
"question": "Where is the cat?",
"correctChoice": "Images/5cats.jpg",
"choice1": "Images/squirrel.png",
"choice2": "Images/beagle.png"
}
]
}
]
模型。这意味着我将为他们的NaiveBayes
的所有行构建train$TN
,为所有train$TN = 4
的行构建NB_TRAIN_model[[1]]
等。但是,该模型将必须基于train$TN = 9
而不是NB_TRAIN_model[[2]]
。因此,我希望我可以使用以下方法排除此值:train$Solar.R, train$Wind, train$Temp, train$Month, train$Day
(请参见最后一行):
train$TN
现在,我想预测测试中的值。我尝试在第一行中使用Ozone ~ . -TN, data = x
:
library(party)
library(e1071)
airq <- subset(airquality, !is.na(Ozone))
## split data to train and test
set.seed(123)
train_ind <- sample(seq_len(nrow(airq)), size = smp_size)
train <- airq[train_ind, ]
test <- airq[-train_ind, ]
ct <- ctree(Ozone ~ ., data = train, controls = ctree_control(maxsurrogate = 3))
train$TN<-factor (ct@where)
## Builds a NB model per each terminal node
NB_TRAIN_model<-lapply(split(train, train$TN), function(x) naiveBayes(Ozone ~ . -TN, data = x))
我得到:
model[[1]]