-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfitness.py
More file actions
30 lines (24 loc) · 973 Bytes
/
fitness.py
File metadata and controls
30 lines (24 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from niaaml.fitness import Precision
from niaaml.data import CSVDataReader
import os
import numpy
"""
This example presents how to use an implemented fitness function and its method individually. In this case, we use Precision for demonstration, but
you can use any of the implemented fitness functions in the same way.
"""
# prepare data reader using csv file
data_reader = CSVDataReader(
src=os.path.dirname(os.path.abspath(__file__)) + "/example_files/dataset.csv",
has_header=False,
contains_classes=True,
)
# lets say the following array contains predictions after the classification process
predictions = numpy.random.choice(
["Class 1", "Class 2"], size=data_reader.get_y().shape
)
# instantiate instance of a fitness function (Precision in this case)
fitness_func = Precision()
# calculate fitness value
precision = fitness_func.get_fitness(predictions, data_reader.get_y())
# precision will probably be low due to dummy data
print(precision)