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}];


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]", 

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:


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

The first row of my data looks like this:


{"[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


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.

  • $\begingroup$ What is the definition of values in train = values[[sample]];? $\endgroup$
    – JimB
    Commented Jan 5, 2018 at 14:47

2 Answers 2


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]]]
  • 1
    $\begingroup$ Alternatively logitAll @@@ test[[All, Range[1,11]]] $\endgroup$
    – Coolwater
    Commented Jan 5, 2018 at 15:27
  • $\begingroup$ @Coolwater Thanks! That's much cleaner. $\endgroup$
    – JimB
    Commented Jan 5, 2018 at 16:23

I think this will work:

vars = {x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11};
logitAll["BestFit"] /. Thread /@ ReleaseHold[Thread[Hold[vars] -> Drop[test, 0, -1]]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.