Reputation: 830
I would like to plot an empirical distribution function using statmodels. I tried what is advised here How to plot empirical cdf (ecdf):
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
price_values = [[4.2],
[4.1],
[4],
[3.8],
[3.9],
[4.2],
[4.5],
[4.8],
[5.2],
[5.2],
[5.2],
[5.6],
[5.2],
[5.1],
[5.3],
[6],
[6.2],
[6.3],
[6.2],
[6],
[5.5] ,
[5.2],
[4.8],
[4.6]]
sample = price_values
ecdf = sm.distributions.ECDF(sample)
x = np.linspace(min(sample), max(sample))
y = ecdf(x)
plt.step(x, y)
plt.show()
Unforunately, the line ecdf = sm.distributions.ECDF(sample)
yields the error "ValueError: x and y do not have the same shape" that I don't understand. Any idea why this error occurs and how to tackle it?
Update: Here is the whole traceback of the error:
Traceback (most recent call last):
File "C:\Users\wi9632\PycharmProjects\building-optimization\src\Plot_EDF.py", line 31, in <module>
ecdf = sm.distributions.ECDF(sample)
File "C:\Users\wi9632\Anaconda3\lib\site-packages\statsmodels\distributions\empirical_distribution.py", line 139, in __init__
super(ECDF, self).__init__(x, y, side=side, sorted=True)
File "C:\Users\wi9632\Anaconda3\lib\site-packages\statsmodels\distributions\empirical_distribution.py", line 89, in __init__
raise ValueError(msg)
ValueError: x and y do not have the same shape
Process finished with exit code 1
Upvotes: 0
Views: 430