Fit_Weibull_2P_grouped show_probability_plot issue
Closed this issue · 2 comments
Hi,
I'd like to fit some failure and censored data, but show_probability_plot = True
return me an error.
This is my code:
# time quantity category
# 0 40.0 1 F
# 1 30.5 1 F
# 2 33.5 1 F
# 3 27.5 1 F
# 4 20.5 1 F
# 5 4.0 1 F
# 6 26.5 1 F
# 7 23.5 1 F
# 8 5.0 1 F
# 9 11.0 1 F
# 10 16.5 1 F
# 11 13.0 1 F
# 12 13.0 1 F
# 13 56.0 23 C
# 14 33.0 94 C
# 15 40.0 93 C
# 16 34.0 111 C
# 17 27.0 36 C
# 18 14.0 96 C
# 19 38.0 123 C
# 20 36.0 117 C
# 21 24.0 111 C
# 22 27.0 36 C
# 23 40.0 93 C
# 24 46.0 12 C
# 25 60.0 17 C
def main():
df = pd.read_excel(io=cfg.XLSX_DATA_FILE, usecols="A:C")
wb = Fit_Weibull_2P_grouped(
dataframe=df,
show_probability_plot=True,
print_result=True,
CI=0.95,
force_beta=None,
initial_guess_method='scipy', # Use MLE method
optimizer='L-BFGS-B', # 'TNC'
CI_type='time')
And this is the errors:
Results from Fit_Weibull_2P_grouped (95% CI):
Point Estimate Standard Error Lower CI Upper CI
Parameter
Alpha 841.936432 718.088263 158.229997 4479.915126
Beta 1.340325 0.350346 0.803000 2.237198
Log-Likelihood: -114.06196026616448
Number of failures: 13
Number of right censored: 962
Fraction censored: 98.66667 %
Traceback (most recent call last):
File "reliasc.py", line 75, in <module>
main()
File "reliasc.py", line 57, in main
wb = Fit_Weibull_2P_grouped(
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\reliability\Fitters.py", line 1194, in __init__
Weibull_probability_plot(failures=failures, right_censored=right_censored, __fitted_dist_params=self, CI=CI, CI_type=CI_type, **kwargs)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\reliability\Probability_plotting.py", line 216, in Weibull_probability_plot
wbf.CDF(label=label, **kwargs)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\reliability\Distributions.py", line 339, in CDF
p = plt.plot(X, cdf, **kwargs)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\pyplot.py", line 2840, in plot
return gca().plot(
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\axes\_axes.py", line 1743, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\axes\_base.py", line 273, in __call__
yield from self._plot_args(this, kwargs)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\axes\_base.py", line 418, in _plot_args
return [func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\axes\_base.py", line 418, in <listcomp>
return [func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\axes\_base.py", line 312, in _makeline
seg = mlines.Line2D(x, y, **kw)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\lines.py", line 390, in __init__
self.update(kwargs)
File "C:\Users\tmonti\AppData\Local\Programs\Python\Python38-32\lib\site-packages\matplotlib\artist.py", line 996, in update
raise AttributeError(f"{type(self).__name__!r} object "
AttributeError: 'Line2D' object has no property 'print_result'
Thank you.
The error is caused by a typo in your input.
When you enter keywords such as color='red' to the fitter, they are passed on to the plot. The reason matplotlib throws an error is because you specified "print_result=True" when you should have used "print_results=True". Because "print_result" is not recognized as an argument, it is treated as a keyword which reliability passes on to matplotlib thereby causing your error. If you fix your typo the error goes away.
On a separate note, you don't need to specify arguments if they are defaults, so you could just write:
df = pd.read_excel(io=filename)
Fit_Weibull_2P_grouped(dataframe=df, initial_guess_method='scipy')
plt.show()
You may notice that your plot is entirely taken up by the confidence intervals which will give you a blue background to the probability plot because the default limits are set based on the scatter plot. Confidence intervals this wide are to be expected with 98.7% censored data. In this case, the probability plot is not a great way to visualize the confidence intervals and you might prefer to plot the CDF without using a probability plot using:
wb=Fit_Weibull_2P_grouped(dataframe=df,show_probability_plot=False,initial_guess_method='scipy')
wb.distribution.CDF()
plt.show()
If you do this, you'll see how wide the confidence bounds are at the 95% confidence level with so much censored data.
You're right! Thank you!
It solved.