Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi readers :),
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!!
Updated 29-Mar-22 15:37pm

1 solution

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.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900