Example #1
0
 def test_exponential_data_produces_correct_inference_no_censorship(self):
     wf = WeibullFitter()
     N = 40000
     T = 5 * np.random.exponential(1, size=N) ** 2
     wf.fit(T)
     assert abs(wf.rho_ - 0.5) < 0.01
     assert abs(wf.lambda_ - 0.2) < 0.01
     assert abs(wf.median_ - 5 * np.log(2) ** 2) < 0.1  # worse convergence
Example #2
0
 def test_weibull_fit_returns_integer_timelines(self):
     wf = WeibullFitter()
     T = np.linspace(0.1, 10)
     wf.fit(T)
     npt.assert_array_equal(wf.timeline,
                            np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
     npt.assert_array_equal(wf.survival_function_.index.values,
                            np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
Example #3
0
 def test_exponential_data_produces_correct_inference_no_censorship(self):
     wf = WeibullFitter()
     N = 40000
     T = 5 * np.random.exponential(1, size=N) ** 2
     wf.fit(T)
     assert abs(wf.rho_ - 0.5) < 0.01
     assert abs(wf.lambda_ - 0.2) < 0.01
     assert abs(wf.median_ - 5 * np.log(2) ** 2) < 0.1  # worse convergence
Example #4
0
 def test_convergence_completes_for_ever_increasing_data_sizes(self):
     wf = WeibullFitter()
     rho = 5
     lambda_ = 1. / 2
     for N in [10, 50, 500, 5000, 50000]:
         T = np.random.weibull(rho, size=N) / lambda_
         wf.fit(T)
         assert abs(1 - wf.rho_ / rho) < 5 / np.sqrt(N)
         assert abs(1 - wf.lambda_ / lambda_) < 5 / np.sqrt(N)
Example #5
0
 def test_convergence_completes_for_ever_increasing_data_sizes(self):
     wf = WeibullFitter()
     rho = 5
     lambda_ = 1. / 2
     for N in [10, 50, 500, 5000, 50000]:
         T = np.random.weibull(rho, size=N) / lambda_
         wf.fit(T)
         assert abs(1 - wf.rho_ / rho) < 5 / np.sqrt(N)
         assert abs(1 - wf.lambda_ / lambda_) < 5 / np.sqrt(N)
Example #6
0
 def test_exponential_data_produces_correct_inference_with_censorship(self):
     wf = WeibullFitter()
     N = 40000
     factor = 5
     T = factor * np.random.exponential(1, size=N)
     T_ = factor * np.random.exponential(1, size=N)
     wf.fit(np.minimum(T, T_), (T < T_))
     assert abs(wf.rho_ - 1.) < 0.05
     assert abs(wf.lambda_ - 1. / factor) < 0.05
     assert abs(wf.median_ - 5 * np.log(2)) < 0.1
Example #7
0
    def test_weibull_model_does_not_except_negative_or_zero_values(self):
        wf = WeibullFitter()

        T = [0, 1, 2, 4, 5]
        with pytest.raises(ValueError):
            wf.fit(T)

        T[0] = -1
        with pytest.raises(ValueError):
            wf.fit(T)
Example #8
0
 def test_exponential_data_produces_correct_inference_with_censorship(self):
     wf = WeibullFitter()
     N = 40000
     factor = 5
     T = factor * np.random.exponential(1, size=N)
     T_ = factor * np.random.exponential(1, size=N)
     wf.fit(np.minimum(T, T_), (T < T_))
     assert abs(wf.rho_ - 1.) < 0.05
     assert abs(wf.lambda_ - 1. / factor) < 0.05
     assert abs(wf.median_ - 5 * np.log(2)) < 0.1
Example #9
0
    def test_weibull_model_does_not_except_negative_or_zero_values(self):
        wf = WeibullFitter()

        T = [0, 1, 2, 4, 5]
        with pytest.raises(ValueError):
            wf.fit(T)

        T[0] = -1
        with pytest.raises(ValueError):
            wf.fit(T)
Example #10
0
 def test_weibull_fit_returns_integer_timelines(self):
     wf = WeibullFitter()
     T = np.linspace(0.1, 10)
     wf.fit(T)
     npt.assert_array_equal(wf.timeline, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
     npt.assert_array_equal(wf.survival_function_.index.values, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))