def test_parametric_plotting_with_show_censors(self, block): n = 200 T = (np.sqrt(50) * np.random.exponential(1, size=n)) ** 2 E = T < 100 T = np.minimum(T, 100) wf = WeibullFitter().fit(T, E) wf.plot_density(show_censors=True) wf.plot_cumulative_density(show_censors=True) self.plt.title("test_parametric_plotting_with_show_censors:cumulative_density") self.plt.show(block=block) wf.plot_survival_function(show_censors=True) self.plt.title("test_parametric_plotting_with_show_censors:survival_function") self.plt.show(block=block) wf.plot_cumulative_hazard(show_censors=True) self.plt.title("test_parametric_plotting_with_show_censors:cumulative_hazard") self.plt.show(block=block) wf.plot_density(show_censors=True) self.plt.title("test_parametric_plotting_with_show_censors:density") self.plt.show(block=block) return
def test_label_can_be_changed_on_univariate_fitters(self, block): T = np.random.exponential(5, size=(2000, 1)) ** 2 wf = WeibullFitter().fit(T, timeline=np.linspace(0, 5)) ax = wf.plot_hazard(label="abc") wf.plot_cumulative_hazard(ax=ax, label="123") self.plt.title("test_label_can_be_changed_on_univariate_fitters") self.plt.show(block=block) return
def test_weibull_plotting(self, block): T = 50 * np.random.exponential(1, size=(200, 1)) ** 2 wf = WeibullFitter().fit(T, timeline=np.linspace(0, 5, 100)) wf.plot_hazard() self.plt.title("test_weibull_plotting:hazard") self.plt.show(block=block) wf.plot_cumulative_hazard() self.plt.title("test_weibull_plotting:cumulative_hazard") self.plt.show(block=block) return
def test_weibull_plotting(self, block): T = np.random.exponential(5, size=(2000, 1))**2 wf = WeibullFitter().fit(T) wf.plot_hazard() self.plt.title("test_weibull_plotting:hazard") self.plt.show(block=block) wf.plot_cumulative_hazard() self.plt.title("test_weibull_plotting:cumulative_hazard") self.plt.show(block=block) return
def test_parametric_plotting_with_show_censors(self, block): n = 200 T = 50 * np.random.exponential(1, size=(n, 1)) ** 2 E = np.random.rand(n) > 0.2 wf = WeibullFitter().fit(T, E, timeline=np.linspace(0, 5, 1000)) wf.plot_cumulative_density(show_censors=True) self.plt.title("test_parametric_plotting_with_show_censors:cumulative_density") self.plt.show(block=block) wf.plot_survival_function(show_censors=True) self.plt.title("test_parametric_plotting_with_show_censors:survival_function") self.plt.show(block=block) wf.plot_cumulative_hazard(show_censors=True) self.plt.title("test_parametric_plotting_with_show_censors:cumulative_hazard") self.plt.show(block=block) return
data = pd.read_csv('Dataset/telco_customer.csv') data['tenure'] = pd.to_numeric(data['tenure']) data = data[data['tenure'] > 0] # Replace yes and No in the Churn column to 1 and 0. 1 for the event and 0 for the censured data. data['Churn'] = data['Churn'].apply(lambda x: 1 if x == 'Yes' else 0) fig, axes = plt.subplots(2, 2, figsize=(16, 12)) T = data['tenure'] E = data['Churn'] wbf = WeibullFitter().fit(T, E, label='WeibullFitter') ef = ExponentialFitter().fit(T, E, label='ExponentialFitter') lnf = LogNormalFitter().fit(T, E, label='LogNormalFitter') llf = LogLogisticFitter().fit(T, E, label='LogLogisticFitter') wbf.plot_cumulative_hazard(ax=axes[0][0]) ef.plot_cumulative_hazard(ax=axes[0][1]) lnf.plot_cumulative_hazard(ax=axes[1][0]) llf.plot_cumulative_hazard(ax=axes[1][1]) plt.suptitle( 'Parametric Model Implementation of the Telco dataset using different models' ) fig.text(0.5, 0.04, 'Timeline', ha='center') fig.text(0.04, 0.5, 'Probability', va='center', rotation='vertical') plt.savefig('Images/WeiExpLogx.jpeg') plt.show()