<p>I've been dabbling with machine learning and neural networks (namely, resnet50) for a few months now, mostly doing image recognition. I am currently trying to make a program that, given a string of numbers as input, can predict the next number in this sequence. For example, the input could be <code>1, 2, 3, 4</code> and the output should be <code>5</code>.</p>

<p>I read something that said this could be done with a multilayer perceptron neural net, but that didn't elaborate much. </p>

<p>Any ideas, or links to tutorials/code?</p>

CC BY-SA 4.0
2020-01-29T11:20:15.950Z
Sequence prediction is very often approached with recurrent neural networks (RNNs). A specific kind of RNN, LSTMs, would be a good choice.
Mathias Müller
CC BY-SA 4.0
2024-07-29T22:33:56.813Z
OEIS reports that there are 12,856 integer sequences beginning with `1,2,3,4` so one must wonder why `5` is the valid answer. If the only rule at work is "add 1 to the previous value," then a neural network does not seem at all necessary to solve the problem.
Sycorax
CC BY-SA 4.0
2024-07-30T05:35:36.300Z
5 is the answer given by the shortest linear prediction from previous values. x(n)=2x(n-1) -x(n-2).
Jaume Oliver Lafont
CC BY-SA 4.0
2024-07-30T05:42:53.723Z
An idea: predict linearly your output values from 1 to N-1 previous samples and choose the minimum length predictor that gets zero error on your data. With your numbers, 2x(n-1)-x(n-2) predicts exactly 3 from 1 2, 4 from 2 3 and 5 from 3 4.
Jaume Oliver Lafont
<neural-networks><machine-learning><prediction><multilayer-perceptrons>
How I can predict the next number in a sequence with a neural network?
c0mraide
# How I can predict the next number in a sequence with a neural network?

(Asked by: username_0 on 2020-01-29)

I've been dabbling with machine learning and neural networks (namely, resnet50) for a few months now, mostly doing image recognition. I am currently trying to make a program that, given a string of numbers as input, can predict the next number in this sequence. For example, the input could be `1, 2, 3, 4` and the output should be `5`.

I read something that said this could be done with a multilayer perceptron neural net, but that didn't elaborate much.

Any ideas, or links to tutorials/code?

**Tags:** neural-networks, machine-learning, prediction, multilayer-perceptrons

> **Comments:**
> **username_1**: Sequence prediction is very often approached with recurrent neural networks (RNNs). A specific kind of RNN, LSTMs, would be a good choice.  
> **username_2**: OEIS reports that there are 12,856 integer sequences beginning with `1,2,3,4` so one must wonder why `5` is the valid answer. If the only rule at work is "add 1 to the previous value," then a neural network does not seem at all necessary to solve the problem.  
> **username_3**: 5 is the answer given by the shortest linear prediction from previous values. x(n)=2x(n-1) -x(n-2).  
> **username_3**: An idea: predict linearly your output values from 1 to N-1 previous samples and choose the minimum length predictor that gets zero error on your data. With your numbers, 2x(n-1)-x(n-2) predicts exactly 3 from 1 2, 4 from 2 3 and 5 from 3 4.  

---

## 0 answers

