# Predicting the outcome on the test data

I have an issue with predicting the outcome variable from the test data based on a fitted model on the training data.

Here is the code:

sample = Sort[RandomSample[Range[nrow], Round[nrow * 0.6]]];
train = values[[sample]];
test = Delete[values, Partition[sample, 1]]; test // Length

logitAll = LogitModelFit[
train, {x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11}, {x1, x2, x3,
x4, x5, x6, x7, x8, x9, x10, x11},
NominalVariables -> {x1, x2, x3, x4, x5, x6, x7, x9, x10, x11}];

logitAll["BestFit"]

1/(1 + E^(2.96427 - 5.04423*10^-6 x8 -
0.168057 DiscreteIndicator[x1,
"[10000,60000]", {"[10000,60000]", "(110000,160000]",
"(160000,210000]", "(210000,260000]", "(260000,360000]",
"(360000,1000000]",...)


There are lot of independent variables and the code is too long, so I cut the rest of the code.

I know that I can predict the outcome variable on my training data using the following code:

logitAll["PredictedResponse"]


But how to predict my dependent variable from my test data?

The first row of my data looks like this:

test[]

{"[10000,60000]", "university", "[0,500]", "[0,500]", "[0,500]",
"[0,500]", "(500,1500]", 0, "no consumption", "paid in full", "paid
in full", 1}


The last variable is the dependent variable.

I tried the following:

logitAll /. test


and

logitAll /. Transpose[Transpose[test][[1 ;; 11]]]


But it does not work. Since this works when there are no nominal variables in the model, I suppose it has to do something with nominal variables, but do not know how to solve this problem.

What should I do? Thank you.

• What is the definition of values in train = values[[sample]];? – JimB Jan 5 '18 at 14:47

Because one can make single predictions in the following manner

logitAll["[10000,60000]", "university", "[0,500]", "[0,500]", "[0,500]",
"[0,500]", "(500,1500]", 0, "no consumption", "paid in full", "paid in full", 1]


This should also work:

logitAll[# /. List -> Sequence] & /@ test[[All, Range[1,11]]]

• Alternatively logitAll @@@ test[[All, Range[1,11]]] – Coolwater Jan 5 '18 at 15:27
• @Coolwater Thanks! That's much cleaner. – JimB Jan 5 '18 at 16:23

I think this will work:

vars = {x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11};