Skip to content

Accept one-dimensional targets in ClassificationKriging - #316

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

antonsoo wants to merge 1 commit into
GeoStat-Framework:mainfrom
antonsoo:fix/classification-target-vector

Conversation

@antonsoo

Copy link
Copy Markdown

ClassificationKriging.fit documents a one-dimensional target, but passes it directly to OneHotEncoder, which requires a column. Reshape the target for the encoder, retaining support for column targets.

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([0, 0, 1, 1])
model = ClassificationKriging(
    classification_model=GaussianNB(),
    n_closest_points=2, variogram_parameters=[1., 0.],
)
model.fit(x, x, y)  # Previously: ValueError: Expected 2D array
print(model.predict(x, x))  # [0 0 1 1]

The regression covers vector and column targets with ordinary and universal kriging. On the recorded Meuse dataset (155 observations), six zero-based vector-target configurations now complete fitting, prediction, and scoring against independent ILR/ordinary-kriging calculations. The corresponding six column-target controls stay exact. The configurations use three stratified splits and seeded logistic/random-forest classifiers.

Validation: the full suite passes (60 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