Open jdmoore7 opened 2 years ago
@jdmoore7, looking at your code there is no parameter gene_type set for the GA constructor. The default gene_type is float, see https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#pygad-ga-class. In your case define gene_type = [int, int, int, float], hopefully that will solve your problem.
I am trying to use PyGAD to optimize hyper-parameters in ML models. According to documentation
As you can see, the first element of
gene_space
, which corresponds tosolution[0]
in the Genetic Algorithm definition, is an array of integers. According to documentation, this should be a discrete space, which it is. However, when this array of integers (fromnp.linspace
, which is okay to use), it is interpreted by Random Forest Classifier as anumpy.float64'>
(see error in 3rd code block.)I don't understand where this change of data type is occurring. Is this a PyGAD problem and how can I fix? Or is it a numpy -> sklearn problem?
The definition of the Genetic Algorithm
And the instantiation of the Genetic Algorithm
Any recommendations on resolving this error?
EDIT: I've tried the below to successful results:
So the issue does not lie with numpy->sklearn but with PyGAD.