python - Scikit 树状图 : How to disable ouput?

标签 python scikit-learn

如果我从 scikit 库运行 dendrogram:

from scipy.cluster.hierarchy import linkage, dendrogram
# ...
X = np.asarray(X)
Z = linkage(X, 'single', 'correlation')
plt.figure(figsize=(16,8))
dendrogram(Z, color_threshold=0.7)

我在 ipython 笔记本中得到了大量print输出:

{'color_list': ['g',
  'r',
  'c',
  'm',
  'y',
   ...
   0.70780175324891315,
   0.70172263980890581],
  [0.0, 0.54342622932769225, 0.54342622932769225, 0.0],
  [0.0, 0.46484932243120658, 0.46484932243120658, 0.0],
  ...
  177,
  196,
  82,
  19,
  108]}

如何禁用此功能?我只对实际的树状图感兴趣。

最佳答案

将打印重定向为空:

import os
import sys
f = open(os.devnull, 'w')
temp = sys.stdout
sys.stdout = f

# print is disabled here

sys.stdout = temp

# print works again!

关于python - Scikit 树状图 : How to disable ouput?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39492171/

相关文章:

python - 为什么我的模型总是准确地获得 0.5 AUC?

python - 简化 Django View 表单处理逻辑

python - 如何在 scikit 学习中对具有多个文本列的数据框进行矢量化而不丢失对原始列的跟踪

python - 使用spark ML 2.2.0中的sklearn-python模型进行预测

python import 会导致代码膨胀。我这里想错了吗?

python - KMeans 如何用于断言数据集有噪声?

python - Sklearn 线性回归 - "IndexError: tuple index out of range"

Python 和 sqlite3 抛出错误 : sqlite3. OperationalError: near "s": syntax error

python - Numpy for windows安装问题

python - NumPy 如何实现其复数字面量?