I tried training this model: All even integers map to T and all odd ones map to F. I used 100 million training examples with Support Vector Machine as the method yet I got garbage for the test cases. Same with all other methods. What am I doing wrong?

  • 1
    $\begingroup$ This is a difficult thing to learn stats.stackexchange.com/q/161189 . You'd need better features if you wanted to learn parity, and that's entirely unnecessary since Mod[x,2] already does the job perfectly. $\endgroup$
    – flinty
    Oct 4, 2020 at 13:33
  • $\begingroup$ Thanks but obviously this example is a proxy for more complicated data that shows rapid oscillations. $\endgroup$ Oct 4, 2020 at 15:36
  • 1
    $\begingroup$ Your question did not mention a proxy model. However, the reasoning still applies. You'd still need more features in the data, even if that meant just getting the binary expansions as feature vectors IntegerDigits[#,2,numdigits]->class[#]&/@numbers $\endgroup$
    – flinty
    Oct 4, 2020 at 15:42

1 Answer 1


This answer is from @GalAster . I simply translate it.


End-to-end double-layer LSTM can

enter image description here

Simple network two-layer LSTM

enter image description here

Automatic loss function, automatic parameter tuning algorithm, cross-validation 10% per round

enter image description here

The test set is a string of numbers below 10^12, the accuracy is 100%, perfect

enter image description here

makeRule[i_] := IntegerString[i] -> If[OddQ@i, "Odd", "Even"];
trainingData = Flatten@Table[makeRule[i], {i, 0, 10000}];
net = NetChain[
    "Input" -> NetEncoder[{"Characters", {DigitCharacter}}],
    "Output" -> NetDecoder[{"Class", {"Odd", "Even"}}]
trained = NetTrain[
    net, trainingData, All,
    MaxTrainingRounds -> 25,
    ValidationSet -> Scaled[0.1],
    TargetDevice -> "GPU"
eval = trained["TrainedNet"];

testingData = Table[makeRule[i], {i, RandomInteger[10^12, 10^4]}];
NetMeasurements[trained["TrainedNet"], testingData, "Accuracy"]

Your Answer

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

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