@@ -405,7 +405,7 @@ solutions within the population.
405
405
population_matrices = gacnn.population_as_matrices(population_networks = GACNN_instance .population_networks, population_vectors = ga_instance.population)
406
406
GACNN_instance .update_population_trained_weights(population_trained_weights = population_matrices)
407
407
408
- print (" Generation = {generation} " .format( generation = ga_instance.generations_completed) )
408
+ print (f " Generation = { ga_instance.generations_completed} " )
409
409
410
410
After preparing the fitness and callback function, next is to create an
411
411
instance of the ``pygad.GA `` class.
@@ -462,7 +462,7 @@ be called to show how the fitness values evolve by generation.
462
462
463
463
ga_instance.plot_fitness()
464
464
465
- .. figure :: https://user-images.githubusercontent.com/16560492/83429675-ab744580-a434-11ea-8f21-9d3804b50d15.png
465
+ .. image :: https://user-images.githubusercontent.com/16560492/83429675-ab744580-a434-11ea-8f21-9d3804b50d15.png
466
466
:alt:
467
467
468
468
Information about the Best Solution
@@ -483,9 +483,9 @@ Here is how such information is returned.
483
483
.. code :: python
484
484
485
485
solution, solution_fitness, solution_idx = ga_instance.best_solution()
486
- print (" Parameters of the best solution : {solution} " .format( solution = solution) )
487
- print (" Fitness value of the best solution = {solution_fitness} " .format( solution_fitness = solution_fitness) )
488
- print (" Index of the best solution : {solution_idx} " .format( solution_idx = solution_idx) )
486
+ print (f " Parameters of the best solution : { solution} " )
487
+ print (f " Fitness value of the best solution = { solution_fitness} " )
488
+ print (f " Index of the best solution : { solution_idx} " )
489
489
490
490
.. code ::
491
491
@@ -504,7 +504,7 @@ the labels correctly.
504
504
.. code :: python
505
505
506
506
predictions = pygad.cnn.predict(last_layer = GANN_instance .population_networks[solution_idx], data_inputs = data_inputs)
507
- print (" Predictions of the trained network : {predictions} " .format( predictions = predictions) )
507
+ print (f " Predictions of the trained network : { predictions} " )
508
508
509
509
Calculating Some Statistics
510
510
---------------------------
@@ -518,9 +518,9 @@ addition to the classification accuracy.
518
518
num_wrong = numpy.where(predictions != data_outputs)[0 ]
519
519
num_correct = data_outputs.size - num_wrong.size
520
520
accuracy = 100 * (num_correct/ data_outputs.size)
521
- print (" Number of correct classifications : {num_correct} ." .format( num_correct = num_correct) )
522
- print (" Number of wrong classifications : {num_wrong} ." .format( num_wrong = num_wrong.size) )
523
- print (" Classification accuracy : {accuracy} ." .format( accuracy = accuracy) )
521
+ print (f " Number of correct classifications : { num_correct} . " )
522
+ print (f " Number of wrong classifications : { num_wrong.size } . " )
523
+ print (f " Classification accuracy : { accuracy} . " )
524
524
525
525
.. code ::
526
526
@@ -575,8 +575,8 @@ complete code is listed below.
575
575
576
576
GACNN_instance .update_population_trained_weights(population_trained_weights = population_matrices)
577
577
578
- print (" Generation = {generation} " .format( generation = ga_instance.generations_completed) )
579
- print (" Fitness = {fitness} " .format( fitness = ga_instance.best_solutions_fitness) )
578
+ print (f " Generation = { ga_instance.generations_completed} " )
579
+ print (f " Fitness = { ga_instance.best_solutions_fitness} " )
580
580
581
581
data_inputs = numpy.load(" dataset_inputs.npy" )
582
582
data_outputs = numpy.load(" dataset_outputs.npy" )
@@ -642,21 +642,21 @@ complete code is listed below.
642
642
643
643
# Returning the details of the best solution.
644
644
solution, solution_fitness, solution_idx = ga_instance.best_solution()
645
- print (" Parameters of the best solution : {solution} " .format( solution = solution) )
646
- print (" Fitness value of the best solution = {solution_fitness} " .format( solution_fitness = solution_fitness) )
647
- print (" Index of the best solution : {solution_idx} " .format( solution_idx = solution_idx) )
645
+ print (f " Parameters of the best solution : { solution} " )
646
+ print (f " Fitness value of the best solution = { solution_fitness} " )
647
+ print (f " Index of the best solution : { solution_idx} " )
648
648
649
649
if ga_instance.best_solution_generation != - 1 :
650
- print (" Best fitness value reached after {best_solution_generation} generations." .format( best_solution_generation = ga_instance.best_solution_generation) )
650
+ print (f " Best fitness value reached after { ga_instance. best_solution_generation} generations. " )
651
651
652
652
# Predicting the outputs of the data using the best solution.
653
653
predictions = GACNN_instance .population_networks[solution_idx].predict(data_inputs = data_inputs)
654
- print (" Predictions of the trained network : {predictions} " .format( predictions = predictions) )
654
+ print (f " Predictions of the trained network : { predictions} " )
655
655
656
656
# Calculating some statistics
657
657
num_wrong = numpy.where(predictions != data_outputs)[0 ]
658
658
num_correct = data_outputs.size - num_wrong.size
659
659
accuracy = 100 * (num_correct/ data_outputs.size)
660
- print (" Number of correct classifications : {num_correct} ." .format( num_correct = num_correct) )
661
- print (" Number of wrong classifications : {num_wrong} ." .format( num_wrong = num_wrong.size) )
662
- print (" Classification accuracy : {accuracy} ." .format( accuracy = accuracy) )
660
+ print (f " Number of correct classifications : { num_correct} . " )
661
+ print (f " Number of wrong classifications : { num_wrong.size } . " )
662
+ print (f " Classification accuracy : { accuracy} . " )
0 commit comments