Exemplo n.º 1
0
class TestRidgeIntegration(TestCase):
  def setUp(self):
    df = pd.read_csv(path.join(BASE_DIR, '../models/categorical-test.csv'))
    Xte = df.iloc[:, 1:]
    Xte = pd.get_dummies(Xte, prefix_sep='')
    del Xte['age(20,30]']
    yte = df.iloc[:, 0]
    self.test = (Xte, yte)

    pmml = path.join(BASE_DIR, '../models/linear-model-ridge.pmml')
    self.clf = PMMLRidge(pmml)

  def test_predict(self):
    Xte, _ = self.test
    ref = np.array([0.56707253, 0.44086932, 0.70106631, 0.63462966, 0.75552995, 0.60126409, 0.4352619 , 0.55362532, 0.40207959, 0.68526355, 0.77666758, 0.53249166, 0.61717879, 0.51593912, 0.49949509, 0.49068951, 0.26094857, 0.71970929, 0.57488419, 0.61499657, 0.6551319 , 0.59615382, 0.42850703, 0.52000645, 0.44016652, 0.42641415, 0.56069061, 0.21493887, 0.17195355, 0.33184511, 0.4237941 , 0.08433666, 0.34454511, 0.26253933, 0.23076609, 0.39833734, 0.35012744, 0.36532649, 0.42733187, 0.42595108, 0.18051046, 0.28151586, 0.25718191, 0.38083643, 0.43149017, 0.46942765, 0.29962233, 0.31491245, 0.49074276, 0.19720312, 0.36989965, 0.41818817])
    assert np.allclose(ref, self.clf.predict(Xte))

  def test_score(self):
    Xte, yte = self.test
    ref = 0.3286660932879891
    assert ref == self.clf.score(Xte, yte == 'Yes')

  def test_fit_exception(self):
    with self.assertRaises(Exception) as cm:
      self.clf.fit(np.array([[]]), np.array([]))

    assert str(cm.exception) == 'Not supported.'
Exemplo n.º 2
0
class TestGeneralRegressionIntegration(TestCase):
    def setUp(self):
        df = pd.read_csv(path.join(BASE_DIR, '../models/categorical-test.csv'))
        Xte = df.iloc[:, 1:]
        yte = df.iloc[:, 0]
        self.test = (Xte, yte)

        pmml = path.join(BASE_DIR, '../models/linear-model-glm.pmml')
        self.clf = PMMLRidge(pmml)

    def test_predict(self):
        Xte, _ = self.test
        ref = np.array([
            0.76984714, 0.62777417, 0.97269501, 0.92573904, 1.07729711,
            0.84270291, 0.49553349, 0.71685506, 0.47088161, 0.97486390,
            1.05130371, 0.61683889, 0.91572548, 0.77157660, 0.62100866,
            0.58980751, 0.23293754, 1.05549000, 0.73136668, 0.91028562,
            0.98442322, 0.76697277, 0.54041194, 0.66282497, 0.55121962,
            0.50143919, 0.76523718, 0.14555227, 0.05832986, 0.33383867,
            0.53914144, -0.11052323, 0.40016843, 0.22597578, 0.14323672,
            0.51625628, 0.36130025, 0.39572621, 0.46020273, 0.52182059,
            -0.00768403, 0.26640930, 0.20815075, 0.38098647, 0.49802258,
            0.56473838, 0.24103994, 0.26506002, 0.52001876, 0.14958276,
            0.38839055, 0.46138168
        ])
        assert np.allclose(ref, self.clf.predict(Xte))

    def test_score(self):
        Xte, yte = self.test
        ref = 0.4791710734180739
        assert ref == self.clf.score(Xte, yte == 'Yes')