5
$\begingroup$

I have a list of 3D points, and I'd like to run a Predict on them just to test. It should be fairly straightforward. Here's a simple example:

trains = {{1, 2, 3} -> {4, 5, 6}, {2, 3, 4} -> {7, 8, 9}};

p = Predict[trains];

ERROR:
Predict: Incompatible variable type (Numerical) and variable value ({4,5,6}).

I'm not sure what I'm doing wrong. Any advise?

$\endgroup$
2
  • 1
    $\begingroup$ It looks as if the outputs (e.g. {4,5,6}) can only be scalar valued. If you want to predict a vector-valued function, perhaps you need a separate predictor for each component. $\endgroup$
    – mikado
    Commented Aug 5, 2016 at 19:36
  • $\begingroup$ Is there no other way to do it? I tried 'Classify' as well, and that gave the same error. $\endgroup$
    – Sham Says
    Commented Aug 5, 2016 at 20:43

2 Answers 2

2
$\begingroup$

In Mathematica 11 you can create such a neural network architecture (seq2seq learning). Desktop version of Mathematica 11 is not available yet, so I have experimented in the Wolfram Cloud.

$Version
11.0.0 for Linux x86 (64-bit) (July 28, 2016)

net=NetChain[{16,3},"Input"->3,"Output"->3]

enter image description here

trains = {{1, 2, 3} -> {4, 5, 6}, {2, 3, 4} -> {7, 8, 9}};

net = NetTrain[net, trains];

net[{1,2,3}]

{4.00003,4.99999,5.99999}

Documentation: http://reference.wolfram.com/language/guide/NeuralNetworks.html

$\endgroup$
4
  • $\begingroup$ This is perfect for me! I'm currently beta testing Wolfram Mathematica 11.0, so this works for me. Is it really that easy to recreate 'Predict' ? I thought Predict used a different way (Logistic Regression, Markov, etc.) based on the data, so is there a way to code in a Logistic Regression or something of the sort? $\endgroup$
    – Sham Says
    Commented Aug 8, 2016 at 1:07
  • $\begingroup$ @ShamSays You can modify V.E.'s code: p = Classify[#, Method -> "LogisticRegression"] & /@ t; $\endgroup$ Commented Aug 8, 2016 at 5:55
  • $\begingroup$ Sorry, I wasn't clear with my question. Is there a way to add a method such as 'LogisticRegression' to the 'NetChain'? $\endgroup$
    – Sham Says
    Commented Aug 8, 2016 at 16:36
  • 1
    $\begingroup$ @ShamSays No. With NetChain you can replicate only Method->"NeuralNetwork" from Classify\Predict. $\endgroup$ Commented Aug 9, 2016 at 2:43
3
$\begingroup$

What the best approach is depends heavily on what you are trying to do. It could be that you don't even need machine learning.

You could construct your own neural network to deal with this kind of input-output. But if you want to use predict you'd have to construct a separate predictor for each component as Mikado comments.

trains = {{1, 2, 3} -> {4, 5, 6}, {2, 3, 4} -> {7, 8, 9}};

t = Transpose@(Table[First@# -> (Last@#)[[i]], {i, 1, 3}] & /@ trains);
p = Predict[#] & /@ t;
f[x_]  := #[x] & /@ p;

Use by calling f, e.g: f[{1,2,3}]:

{4., 5., 6.}

Whether this is a good approach for your problem is impossible to tell due to the lack of information.

$\endgroup$

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.