Пример #1
0
 def test_exceptions(self):
     mod_not_fit = RandomForestRegressor()
     # dataset should be compatible with the model
     with self.assertRaises(Exception) as mod_ex_2:
         aleplot_1D_discrete(self.X, mod_not_fit, "x4")
     mod_ex_msg = "Please check that your model is fitted, and accepts X as input."
     self.assertEqual(mod_ex_2.exception.args[0], mod_ex_msg)
Пример #2
0
 def test_binsizes(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=False)
     self.assertCountEqual(ale_eff.loc[:, "size"],
                           [27, 14, 16, 26, 20, 17, 18, 23, 21, 18])
Пример #3
0
 def test_outputshape_noCI(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=False)
     self.assertEqual(ale_eff.shape, (10, 2))
     self.assertCountEqual(ale_eff.columns, ["eff", "size"])
Пример #4
0
 def test_1D_continuous_bar_plot(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=True)
     fig, ax, ax2 = plot_1D_discrete_eff(ale_eff, self.X)
     self.assertCountEqual(ale_eff['size'],
                           [bar.get_height() for bar in ax2.patches])
Пример #5
0
 def test_1D_continuous_line_plot(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=True)
     fig, ax, ax2 = plot_1D_discrete_eff(ale_eff, self.X)
     self.assertCountEqual(ax.lines[0].get_xydata()[:, 0], ale_eff.index)
     self.assertCountEqual(ax.lines[0].get_xydata()[:, 1], ale_eff.eff)
Пример #6
0
 def test_bins(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=False)
     self.assertCountEqual(
         ale_eff.index,
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
     )
Пример #7
0
 def test_outputshape_withCI(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=True,
                                   C=0.9)
     self.assertEqual(ale_eff.shape, (10, 4))
     self.assertCountEqual(ale_eff.columns,
                           ["eff", "size", "lowerCI_90%", "upperCI_90%"])
Пример #8
0
 def test_1D_continuous_ci_plot(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=True)
     fig, ax, ax2 = plot_1D_discrete_eff(ale_eff, self.X)
     self.assertCountEqual(np.round(ax.lines[1].get_xydata()[1:, 1], 8),
                           np.round(ale_eff['lowerCI_95%'][1:], 8))
     self.assertCountEqual(np.round(ax.lines[2].get_xydata()[1:, 1], 8),
                           np.round(ale_eff['upperCI_95%'][1:], 8))
Пример #9
0
 def test_effvalues(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=False)
     self.assertCountEqual(
         np.round(ale_eff.loc[:, "eff"], 8),
         [
             -1.20935606,
             -0.82901158,
             -0.42415507,
             -0.24192617,
             0.04098572,
             0.32370623,
             0.56468117,
             0.61378063,
             0.6786663,
             0.69330051,
         ],
     )
Пример #10
0
 def test_effvalues(self):
     ale_eff = aleplot_1D_discrete(X=self.X_cleaned,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=False)
     self.assertCountEqual(
         np.round(ale_eff.loc[:, "eff"], 8),
         [
             -1.15833245,
             -0.87518863,
             -0.17627267,
             -0.03183705,
             0.21772015,
             0.3103579,
             0.37654819,
             0.38187692,
             0.54013521,
             0.59118777,
         ],
     )
Пример #11
0
 def test_CIvalues(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=True,
                                   C=0.9)
     # assert that the first bin do not have a CI
     self.assertTrue(np.isnan(ale_eff.loc[ale_eff.index[0], "lowerCI_90%"]))
     self.assertTrue(np.isnan(ale_eff.loc[ale_eff.index[0], "upperCI_90%"]))
     # check the values of the CI
     self.assertCountEqual(
         np.round(ale_eff.loc[ale_eff.index[1]:, "lowerCI_90%"], 8),
         [
             -0.91916875,
             -0.54755861,
             -0.29067159,
             -0.04528913,
             0.2512252,
             0.48115024,
             0.58654446,
             0.65270079,
             0.66807024,
         ],
     )
     self.assertCountEqual(
         np.round(ale_eff.loc[ale_eff.index[1]:, "upperCI_90%"], 8),
         [
             -0.73885441,
             -0.30075154,
             -0.19318075,
             0.12726056,
             0.39618726,
             0.6482121,
             0.64101679,
             0.70463181,
             0.71853079,
         ],
     )
Пример #12
0
 def test_CIvalues(self):
     ale_eff = aleplot_1D_discrete(X=self.X_cleaned,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=True,
                                   C=0.9)
     # assert that the first bin do not have a CI
     self.assertTrue(np.isnan(ale_eff.loc[ale_eff.index[0], "lowerCI_90%"]))
     self.assertTrue(np.isnan(ale_eff.loc[ale_eff.index[0], "upperCI_90%"]))
     # check the values of the CI
     self.assertCountEqual(
         np.round(ale_eff.loc[ale_eff.index[1]:, "lowerCI_90%"], 8),
         [
             -0.92693686,
             -0.30837293,
             -0.05872927,
             0.17298345,
             0.23835091,
             0.34097451,
             0.35996381,
             0.47381797,
             0.56927921,
         ],
     )
     self.assertCountEqual(
         np.round(ale_eff.loc[ale_eff.index[1]:, "upperCI_90%"], 8),
         [
             -0.8234404,
             -0.0441724,
             -0.00494484,
             0.26245684,
             0.38236488,
             0.41212186,
             0.40379003,
             0.60645245,
             0.61309633,
         ],
     )
Пример #13
0
 def test_indexname(self):
     ale_eff = aleplot_1D_discrete(X=self.X,
                                   model=self.model,
                                   feature="x4",
                                   include_CI=False)
     self.assertEqual(ale_eff.index.name, "x4")