我正在尝试使用ggplot创建一个情节,我不知道为什么我会收到此错误。这是代码:
from ggplot import *
ggplot(counts, aes(x='pred_prob',y='true_prob',size='count')) + \
geom_point(color='blue') + \
stat_function(fun=lambda x: x, color='red') + \
xlim(-0.05, 1.05) + ylim(-0.05,1.05)
这是我得到的错误:
NameError Traceback (most recent call last)
<ipython-input-71-fdefd49237a1> in <module>()
2
3 baseline = np.mean(is_churn)
----> 4 ggplot(counts, aes(x='pred_prob',y='true_prob',size='count')) + geom_point(color='blue') + stat_function(fun=lambda x: x, color='red') + xlim(-0.05, 1.05) + ylim(-0.05,1.05)
NameError: name 'stat_function' is not defined
我不知道为什么我会收到这个错误。有任何想法吗?我正在使用python 3.5.2和ggplot版本0.11.5
答案 0 :(得分:1)
我从同一个确切示例code
中得到了同样的错误ggplot库似乎经历了重构。
要安装该版本,请使用:
pip install -U git+https://github.com/yhat/ggpy.git@v0.6.6
然后
from ggplot import *
from ggplot.stats.stat_function import stat_function # added line
import pandas as pd
%matplotlib inline
ggplot(pd.DataFrame({'x':[0,500]}), aes(x='x')) + \
stats.stat_function(fun = lambda x: 50. / (x + 50.)) + \
ggtitle("Epsilon decay over time") + \
xlab("amount of feedback") + ylab("epsilon (probability of testing)")
它将产生与帖子中相同的数字