Skip to content

Commit 374029c

Browse files
committed
Test calibratedModel and fixed parameter method
1 parent 3274d6a commit 374029c

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

pycalib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.9.dev8'
1+
__version__ = '0.0.9.dev9'

pycalib/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ class _CalibratedClassifier(object):
612612
def __init__(self, base_estimator, method='beta',
613613
score_type=None):
614614
self.base_estimator = base_estimator
615-
self.calibrator = method
615+
self.method = method
616616
self.score_type = score_type
617617

618618
def _preproc(self, X):

pycalib/tests/models/test_init.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import unittest
22
import numpy as np
3+
from sklearn.linear_model import LogisticRegression
4+
from sklearn.datasets import make_blobs
35
from pycalib.models import (IsotonicCalibration, LogisticCalibration,
4-
BinningCalibration, SigmoidCalibration)
6+
BinningCalibration, SigmoidCalibration,
7+
CalibratedModel)
58
from numpy.testing import assert_array_equal
69

710

811
class TestIsotonicCalibration(unittest.TestCase):
9-
def test_dummy(self):
12+
def test_fit_predict(self):
1013
S = np.array([[0.1, 0.9], [0.6, 0.4]])
1114
Y = np.array([1, 0])
1215
cal = IsotonicCalibration()
@@ -16,7 +19,7 @@ def test_dummy(self):
1619

1720

1821
class TestLogisticCalibration(unittest.TestCase):
19-
def test_dummy(self):
22+
def test_fit_predict(self):
2023
S = np.array([[0.1, 0.9], [0.6, 0.4]])
2124
Y = np.array([1, 0])
2225
cal = LogisticCalibration()
@@ -26,7 +29,7 @@ def test_dummy(self):
2629

2730

2831
class TestBinningCalibration(unittest.TestCase):
29-
def test_dummy(self):
32+
def test_fit_predict(self):
3033
S = np.array([[0.1, 0.9], [0.6, 0.4]])
3134
Y = np.array([1, 0])
3235
cal = BinningCalibration()
@@ -36,7 +39,7 @@ def test_dummy(self):
3639

3740

3841
class TestSigmoidCalibration(unittest.TestCase):
39-
def test_dummy(self):
42+
def test_fit_predict(self):
4043
S = np.array([[0.1, 0.9], [0.6, 0.4]])
4144
Y = np.array([1, 0])
4245
cal = SigmoidCalibration()
@@ -45,6 +48,18 @@ def test_dummy(self):
4548
assert_array_equal(Y, pred)
4649

4750

51+
class TestCalibratedModel(unittest.TestCase):
52+
def test_fit_predict(self):
53+
X, Y = make_blobs(n_samples=10000, centers=5, n_features=2,
54+
random_state=42)
55+
Y = (Y > 2).astype(int)
56+
cal = CalibratedModel(LogisticRegression(), IsotonicCalibration())
57+
cal.fit(X, Y)
58+
59+
pred = cal.predict(X)
60+
self.assertGreater(np.mean(Y == pred), 0.7)
61+
62+
4863
def main():
4964
unittest.main()
5065

0 commit comments

Comments
 (0)