11import unittest
22import numpy as np
3+ from sklearn .linear_model import LogisticRegression
4+ from sklearn .datasets import make_blobs
35from pycalib .models import (IsotonicCalibration , LogisticCalibration ,
4- BinningCalibration , SigmoidCalibration )
6+ BinningCalibration , SigmoidCalibration ,
7+ CalibratedModel )
58from numpy .testing import assert_array_equal
69
710
811class 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
1821class 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
2831class 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
3841class 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+
4863def main ():
4964 unittest .main ()
5065
0 commit comments