|
| 1 | +# |
| 2 | +# Copyright (C) 2025 sits developers. |
| 3 | +# |
| 4 | +# This program is free software; you can redistribute it and/or modify it |
| 5 | +# under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation; either version 2 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# This program is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 16 | +# |
| 17 | + |
| 18 | +"""Unit tests for validation operations (cube and time-series).""" |
| 19 | + |
| 20 | +from pysits.models import SITSConfusionMatrix, SITSNamedVector, SITSTable |
| 21 | +from pysits.sits.context import cerrado_2classes |
| 22 | +from pysits.sits.ml import sits_rfor |
| 23 | +from pysits.sits.ts import sits_sample, sits_validate |
| 24 | + |
| 25 | + |
| 26 | +def test_sits_validate(): |
| 27 | + """Test validate operation.""" |
| 28 | + |
| 29 | + # Sample data |
| 30 | + samples = sits_sample(cerrado_2classes, frac=0.5) |
| 31 | + samples_validation = sits_sample(cerrado_2classes, frac=0.5) |
| 32 | + |
| 33 | + # Validate samples |
| 34 | + matrix = sits_validate( |
| 35 | + samples=samples, samples_validation=samples_validation, ml_method=sits_rfor() |
| 36 | + ) |
| 37 | + |
| 38 | + # Check properties |
| 39 | + assert isinstance(matrix, SITSConfusionMatrix) |
| 40 | + assert isinstance(matrix.by_class, SITSNamedVector) |
| 41 | + assert isinstance(matrix.dots, list) |
| 42 | + assert isinstance(matrix.mode, str) |
| 43 | + assert isinstance(matrix.overall, SITSNamedVector) |
| 44 | + assert isinstance(matrix.table, SITSTable) |
| 45 | + |
| 46 | + # Check values |
| 47 | + assert matrix.mode == "sens_spec" |
| 48 | + assert matrix.positive == "Cerrado" |
0 commit comments