H2O - savefig "performance.plot()" ROC
H2O - savefig with "performance.plot()" ROC
当我使用H2O 3.19时,我想在服务器端保存训练数据的性能matplotlib.pyplot
图形(ROC),我该怎么做?
这里可以看到plot()
的源码在h2o/model/metrics_base.py
:
def plot(self, type="roc", server=False):
"""
Produce the desired metric plot.
:param type: the type of metric plot (currently, only ROC supported).
:param server: if True, generate plot inline using matplotlib's "Agg" backend.
:returns: None
"""
# TODO: add more types (i.e. cutoffs)
assert_is_type(type, "roc")
# check for matplotlib. exit if absent.
try:
imp.find_module('matplotlib')
import matplotlib
if server: matplotlib.use('Agg', warn=False)
import matplotlib.pyplot as plt
except ImportError:
print("matplotlib is required for this function!")
return
if type == "roc":
plt.xlabel('False Positive Rate (FPR)')
plt.ylabel('True Positive Rate (TPR)')
plt.title('ROC Curve')
plt.text(0.5, 0.5, r'AUC={0:.4f}'.format(self._metric_json["AUC"]))
plt.plot(self.fprs, self.tprs, 'b--')
plt.axis([0, 1, 0, 1])
if not server: plt.show()
plot(type="roc", server=False)
只是检查 matplotlib.pyplot
的存在,而不是 return plt
对象,所以我不能调用 plt.savefig()
。我能做什么?
正如@Goyo的评论所说,你需要在调用plot()
方法的地方引入matplotlib.pyplot
,你可以在那里savefig
。似乎没有 return 它仍然是可能的,所以我猜信息是在 "inside" 和 "outside" 之间共享的,即他们在 [=30] 中说 "static" =] 方式。
最后只好修改源码,在server is True
时强制为returnplt
,然后在外面调用plot(type="roc", server=True)
.我认为它没有影响,因为在更改之前,默认情况下它 returns None
.
if not server:
plt.show()
else:
return plt # return to use plt.savefig
当我使用H2O 3.19时,我想在服务器端保存训练数据的性能matplotlib.pyplot
图形(ROC),我该怎么做?
这里可以看到plot()
的源码在h2o/model/metrics_base.py
:
def plot(self, type="roc", server=False):
"""
Produce the desired metric plot.
:param type: the type of metric plot (currently, only ROC supported).
:param server: if True, generate plot inline using matplotlib's "Agg" backend.
:returns: None
"""
# TODO: add more types (i.e. cutoffs)
assert_is_type(type, "roc")
# check for matplotlib. exit if absent.
try:
imp.find_module('matplotlib')
import matplotlib
if server: matplotlib.use('Agg', warn=False)
import matplotlib.pyplot as plt
except ImportError:
print("matplotlib is required for this function!")
return
if type == "roc":
plt.xlabel('False Positive Rate (FPR)')
plt.ylabel('True Positive Rate (TPR)')
plt.title('ROC Curve')
plt.text(0.5, 0.5, r'AUC={0:.4f}'.format(self._metric_json["AUC"]))
plt.plot(self.fprs, self.tprs, 'b--')
plt.axis([0, 1, 0, 1])
if not server: plt.show()
plot(type="roc", server=False)
只是检查 matplotlib.pyplot
的存在,而不是 return plt
对象,所以我不能调用 plt.savefig()
。我能做什么?
正如@Goyo的评论所说,你需要在调用plot()
方法的地方引入matplotlib.pyplot
,你可以在那里savefig
。似乎没有 return 它仍然是可能的,所以我猜信息是在 "inside" 和 "outside" 之间共享的,即他们在 [=30] 中说 "static" =] 方式。
最后只好修改源码,在server is True
时强制为returnplt
,然后在外面调用plot(type="roc", server=True)
.我认为它没有影响,因为在更改之前,默认情况下它 returns None
.
if not server:
plt.show()
else:
return plt # return to use plt.savefig