Получение ошибки ggplot (python) NameError: имя 'stat_function' не определено

Я пытаюсь построить график с помощью 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


person Imu    schedule 31.01.2017    source источник


Ответы (1)


Я получил ту же самую ошибку из того же точного примера кода

похоже, библиотека ggplot прошла рефакторинг.

Чтобы установить эту версию, используйте:

pip install -U git+https://github.com/yhat/[email protected]

а потом

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)")

Будет получена такая же цифра, как в посте

введите здесь описание изображения

person fabrizioM    schedule 08.03.2017
comment
При попытке загрузить pip install -U git+https://github.com/yhat/[email protected] с jupyter возникла ошибка. Есть идеи, что я делаю неправильно? The error is: File "<ipython-input-45-9ef0b572dfaf>", line 1 pip install -U git+https://github.com/yhat/[email protected] ^ SyntaxError: invalid syntax - person nak5120; 06.04.2017
comment
Выполните эту команду в командной строке, а не в записной книжке. - person Hendrik Wiese; 09.11.2017