Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable feature validation on sklearn predict prob. #5953

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def predict(self, data, output_margin=False, ntree_limit=None,
'Label encoder is not defined. Returning class probability.')
return class_probs

def predict_proba(self, data, ntree_limit=None, validate_features=True,
def predict_proba(self, data, ntree_limit=None, validate_features=False,
base_margin=None):
"""
Predict the probability of each `data` example being of a given class.
Expand Down
32 changes: 32 additions & 0 deletions tests/python/test_with_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,38 @@ def test_parameter_validation():
assert len(output) == 0


@pytest.mark.skipif(**tm.no_pandas())
def test_pandas_input():
import pandas as pd
from sklearn.calibration import CalibratedClassifierCV
rng = np.random.RandomState(1994)

kRows = 100
kCols = 6

X = rng.randint(low=0, high=2, size=kRows*kCols)
X = X.reshape(kRows, kCols)

df = pd.DataFrame(X)
feature_names = []
for i in range(1, kCols):
feature_names += ['k'+str(i)]

df.columns = ['status'] + feature_names

target = df['status']
train = df.drop(columns=['status'])
model = xgb.XGBClassifier()
model.fit(train, target)
clf_isotonic = CalibratedClassifierCV(model,
cv='prefit', method='isotonic')
clf_isotonic.fit(train, target)
assert isinstance(clf_isotonic.calibrated_classifiers_[0].base_estimator,
xgb.XGBClassifier)
np.testing.assert_allclose(np.array(clf_isotonic.classes_),
np.array([0, 1]))


class TestBoostFromPrediction(unittest.TestCase):
def run_boost_from_prediction(self, tree_method):
from sklearn.datasets import load_breast_cancer
Expand Down