diff --git a/src/pykrige/ck.py b/src/pykrige/ck.py index 4199c87..20dd3c4 100644 --- a/src/pykrige/ck.py +++ b/src/pykrige/ck.py @@ -167,7 +167,7 @@ def predict(self, p, x, **kwargs): pred_proba_ilr = self.krige_residual(x, **kwargs) + ml_pred_ilr pred_proba = inverse_ilr_transformation(pred_proba_ilr) - return np.argmax(pred_proba, axis=1) + return self.classes_[np.argmax(pred_proba, axis=1)] def krige_residual(self, x, **kwargs): """ diff --git a/tests/test_classification_krige.py b/tests/test_classification_krige.py index 9110a97..c346253 100644 --- a/tests/test_classification_krige.py +++ b/tests/test_classification_krige.py @@ -62,6 +62,37 @@ def test_classification_krige(): assert class_model.score(X_test, lon_lat_test, y_test) > 0.25 +@pytest.mark.skipif(not SKLEARN_INSTALLED, reason="requires scikit-learn") +@pytest.mark.parametrize("method", ["ordinary", "universal"]) +@pytest.mark.parametrize( + "classes", + [ + np.array([1, 3, 7]), + np.array([-4, -2, 5]), + np.array(["clay", "peat", "sand"]), + np.arange(3), + ], +) +def test_classification_krige_prediction_labels(method, classes): + rng = np.random.RandomState(4) + p = rng.uniform(size=(12, 2)) + x = rng.uniform(size=(12, 2)) + y = classes[np.arange(12) % 3] + model = ClassificationKriging( + classification_model=RandomForestClassifier(n_estimators=8, random_state=0), + method=method, + n_closest_points=4, + variogram_parameters=[1.0, 0.0], + ) + model.fit(p, x, y[:, None]) + + prediction = model.predict(p, x) + np.testing.assert_array_equal(prediction, y) + assert prediction.shape == y.shape + assert prediction.dtype == y.dtype + assert model.score(p, x, y) == 1.0 + + @pytest.mark.skipif(not SKLEARN_INSTALLED, reason="requires scikit-learn") def test_krige_classification_housing(): import ssl