Skip to content

Preserve class labels in ClassificationKriging predictions - #317

Open
antonsoo wants to merge 1 commit into
GeoStat-Framework:mainfrom
antonsoo:fix/classification-prediction-labels
Open

antonsoo wants to merge 1 commit into
GeoStat-Framework:mainfrom
antonsoo:fix/classification-prediction-labels

Conversation

@antonsoo

Copy link
Copy Markdown

ClassificationKriging.predict returns probability-column indices rather than fitted class labels. Use classes_ to decode the winning column, so nonconsecutive integers and text labels survive prediction and score compares the original labels.

import numpy as np
from sklearn.naive_bayes import GaussianNB
from pykrige.ck import ClassificationKriging

x = np.array([[0., 0.], [0., 1.], [1., 0.], [1., 1.]])
y = np.array([10, 10, 20, 20])
model = ClassificationKriging(
    classification_model=GaussianNB(),
    n_closest_points=2, variogram_parameters=[1., 0.],
)
model.fit(x, x, y[:, None])
print(model.predict(x, x))  # Before: [0 0 1 1]; after: [10 10 20 20]
print(model.score(x, x, y))  # Before: 0.0; after: 1.0

Regressions cover nonzero, negative, text, and zero-based labels with ordinary and universal kriging. On 155 recorded Meuse observations, 18 configurations with original soil IDs or explicitly recoded labels now match independently decoded ILR/kriging predictions; six zero-based controls stay exact. Classifier probabilities and kriged residuals remain unchanged. This corrects label semantics, with no claim of improved statistical modelling.

Validation: the full suite passes (64 tests) with Python 3.12 / NumPy 2.5 / scikit-learn 1.9 and Python 3.10 / NumPy 1.21.6 / scikit-learn 1.0.2. Black, isort, cython-lint, and git diff --check pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant