myco.metrics¶
Metrics for evaluating model performance and during and after model training. Metrics are a superset of loss functions - all losses are metrics, but not all metrics are losses. This is because a loss must decrease in value to indicate an increase in model performance. R-squared is an example of a metric that is not a loss - an increase in r2 corresponds to better performance. Losses and Metrics are also independent python object types that have different assumptions regarding subclasses and class functions.
MycoMetric
¶
Bases: tf.keras.metrics.Metric
Common methods to attach to metrics, like nodata filtering.
Source code in myco/metrics.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
__init__(name=None, nodata=None, greater_than=None, less_than=None, scaler=None, dtype=tf.float32, is_categorical=False, **kwargs)
¶
Create a custom metric function that filters input data prior to the calculation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the metric (logged in model training) |
None
|
nodata |
float
|
the nodata value to exclude from calculations. |
None
|
greater_than |
float
|
only include values above this threshold. |
None
|
less_than |
float
|
only include values below this threshold. |
None
|
scaler |
TFScaler
|
apply inverse_transform methods to rescale data |
None
|
dtype |
tf.dtypes.DType
|
the tf data type to compute the metric in. |
tf.float32
|
is_categorical |
bool
|
add base categorical states for computing confusion matrix statistics |
False
|
Source code in myco/metrics.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
filter_greater_than(y_true, y_pred, sample_weight)
¶
Removes values below the greater_than
threshold from tensors
Source code in myco/metrics.py
138 139 140 141 142 143 144 145 146 147 148 149 |
|
filter_less_than(y_true, y_pred, sample_weight)
¶
Removes values above the less_than
threshold from tensors
Source code in myco/metrics.py
151 152 153 154 155 156 157 158 159 160 161 162 |
|
filter_nodata(y_true, y_pred, sample_weight)
¶
Removes nodata values from y_true and y_pred tensors
Source code in myco/metrics.py
125 126 127 128 129 130 131 132 133 134 135 136 |
|
format_categorical(y_true, y_pred, sample_weight=None)
¶
Compute categorical confusion matrix components
Source code in myco/metrics.py
114 115 116 117 118 119 120 121 122 123 |
|
format_tensors(y_true, y_pred, sample_weight)
¶
Ensure consistent data types, shapes, and weights values for all inputs
Source code in myco/metrics.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
get_metric(name)
¶
Returns an un-initialized metric object by name.
Source code in myco/metrics.py
800 801 802 803 |
|
get_names()
¶
Returns a list of the available metrics supported in configuration.
Source code in myco/metrics.py
795 796 797 |
|