15,919,434 members
1.00/5 (1 vote)
See more: , +
I read this article at Genetic Algorithm: General Concept, Matlab Code, and Example[^] . Basically, the genetic algorithm code used in this case is from an output given, it can predict the 2 different variables. For example, if I use 3*x+2*y=5, it will guess what is the best x and y to fit into this equality.

Question: How to modify the code in the link so that the genetic algorithm can predict the outcome of a function given 2 random inputs from the user? This is more towards data regression

What I have tried:

I have tried to search article on data regression using Genetic Algorithm but couldn't find any. Can anyone share some articles valid to data regression on this algorithm. Thanks for helping!!
Posted
Updated 29-Mar-22 15:37pm

## Solution 1

There's 2 big obstacles here you will have to face:

First, 3*x + 2*y = 5 is underdetermined. Choose any x, and there is a y that will satisfy the equation. The genetic algorithm is for optimization. You need to pose this as an optimization problem. So the nearest related problem that the genetic algorithm is suitable for would be a linear regression like:

ax + by = c

where x and y are scalars. a, b and c are vectors of some length n. You suppose that you know n, a, b, and c and seek x and y that minimize the error. This problem has a very well-known solution, the method of least squares. You could use the least-squares solution to check if your genetic algorithm is working.

Second, the genetic algorithm uses a lot of computer power. JavaScript is scripting language, and therefore inefficient. To write efficient code, you need to write in a compiled language.