@@ -16,8 +16,8 @@ def fitness_func(ga_instanse, solution, sol_idx):
16
16
return solution_fitness
17
17
18
18
def on_generation (ga_instance ):
19
- print ("Generation = {generation}" . format ( generation = ga_instance .generations_completed ) )
20
- print ("Fitness = {fitness}" . format ( fitness = ga_instance .best_solution ()[1 ]) )
19
+ print (f "Generation = { ga_instance .generations_completed } " )
20
+ print (f "Fitness = { ga_instance .best_solution ()[1 ]} " )
21
21
22
22
# Build the keras model using the functional API.
23
23
input_layer = tensorflow .keras .layers .Input (360 )
@@ -57,8 +57,8 @@ def on_generation(ga_instance):
57
57
58
58
# Returning the details of the best solution.
59
59
solution , solution_fitness , solution_idx = ga_instance .best_solution ()
60
- print ("Fitness value of the best solution = {solution_fitness}" . format ( solution_fitness = solution_fitness ) )
61
- print ("Index of the best solution : {solution_idx}" . format ( solution_idx = solution_idx ) )
60
+ print (f "Fitness value of the best solution = { solution_fitness } " )
61
+ print (f "Index of the best solution : { solution_idx } " )
62
62
63
63
# Fetch the parameters of the best solution.
64
64
predictions = pygad .kerasga .predict (model = model ,
@@ -68,13 +68,13 @@ def on_generation(ga_instance):
68
68
69
69
# Calculate the categorical crossentropy for the trained model.
70
70
cce = tensorflow .keras .losses .CategoricalCrossentropy ()
71
- print ("Categorical Crossentropy : " , cce (data_outputs , predictions ).numpy ())
71
+ print (f "Categorical Crossentropy : { cce (data_outputs , predictions ).numpy ()} " )
72
72
73
73
# Calculate the classification accuracy for the trained model.
74
74
ca = tensorflow .keras .metrics .CategoricalAccuracy ()
75
75
ca .update_state (data_outputs , predictions )
76
76
accuracy = ca .result ().numpy ()
77
- print ("Accuracy : " , accuracy )
77
+ print (f "Accuracy : { accuracy } " )
78
78
79
79
# model.compile(optimizer="Adam", loss="mse", metrics=["mae"])
80
80
0 commit comments