Classification API¶
obia.classification.classify¶
obia.classification.classify
¶
ClassifiedImage
¶
class ClassifiedImage
Represents an image along with its classification results and associated properties.
classified: The classified image data. confusion_matrix: The confusion matrix of the classification results. report: A detailed report of the classification results. params: The parameters used during classification. shap_values: SHAP values for the classification results. crs: Coordinate Reference System for the image. transform: Affine transform parameters for the image.
def init(self, classified, confusion_matrix, report, shap_values, transform, crs, params): Initializes a new instance of the ClassifiedImage class.
1 2 3 4 5 6 7 8 | |
def write_geotiff(self, output_path): Writes the classified image to a GeoTIFF file.
1 2 | |
Source code in obia/classification/classify.py
11 12 13 14 15 16 17 18 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 | |
write_geotiff(output_path)
¶
:param output_path: Path where the GeoTIFF file will be saved. :return: None
Source code in obia/classification/classify.py
59 60 61 62 63 64 | |
classify(segments, training_classes, acceptable_classes_gdf=None, method='rf', test_size=0.2, compute_reports=False, compute_shap=False, sample_shap=False, **kwargs)
¶
:param segments: A GeoDataFrame containing the segments to be classified. :param training_classes: A DataFrame containing the training data with 'feature_class' as the target variable. :param acceptable_classes_gdf: A GeoDataFrame of acceptable classes with geometries to mask predictions. Default is None. :param method: The machine learning method to use for classification ('rf' for RandomForest, 'mlp' for MLPClassifier). Default is 'rf'. :param test_size: The proportion of the dataset to include in the test split. Default is 0.5. :param compute_reports: Whether to compute and return classification reports and confusion matrix. Default is False. :param compute_shap: Whether to compute and return SHAP values for feature importance. Default is False. :param kwargs: Additional keyword arguments passed to the classifier. :return: An object of ClassifiedImage containing the classified segments, confusion matrix, classification report, SHAP values, and classifier parameters.
Source code in obia/classification/classify.py
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 180 181 182 | |