我试图通过在 pandas 数据框中创建 scatter_matrix 来显示一对图。这就是配对图的创建方式:
# Create dataframe from data in X_train
# Label the columns using the strings in iris_dataset.feature_names
iris_dataframe = pd.DataFrame(X_train, columns=iris_dataset.feature_names)
# Create a scatter matrix from the dataframe, color by y_train
grr = pd.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15), marker='o',
hist_kwds={'bins': 20}, s=60, alpha=.8, cmap=mglearn.cm3)
我想显示成对图看起来像这样;
我使用的是 Python v3.6 和 PyCharm ,没有使用 Jupyter Notebook。
原文由 user3848207 发布,翻译遵循 CC BY-SA 4.0 许可协议
此代码使用 Python 3.5.2 对我有用:
对于熊猫版本 < v0.20.0。
感谢 michael-szczepaniak 指出此 API 已被弃用。
我只需要删除
cmap=mglearn.cm3
部分,因为我无法使 mglearn 工作。 sklearn 存在版本不匹配问题。要不显示图像并将其直接保存到文件中,您可以使用以下方法:
同时删除