2017-09-15 217 views
0

有我的代碼(書中關於機器學習的代碼示例),但最終並沒有出現pd.plotting.scatter_matrix。Python熊貓繪製

import sys 
import mglearn as mglearn 
import pandas as pd 
from pandas.plotting import scatter_matrix 
import tkinter 
import matplotlib 
import numpy as np 
import scipy as sp 
import IPython 
import sklearn 
from sklearn.datasets import load_iris 
from sklearn.model_selection import train_test_split 

iris_dataset = load_iris() 
print("Ключи iris_datasets: \n{}".format(iris_dataset.keys())) 
print(iris_dataset['DESCR'][:193] + "\n...") 
print("Названия ответов: {}".format(iris_dataset['target_names'])) 
print("Первые пять строк массива data:\n{}".format(iris_dataset['data'][:5])) 
X_train, X_test, y_train, y_test = train_test_split(
iris_dataset['data'], iris_dataset['target'], random_state=0) 

# print("X: \n" + format(X_train)) 

iris_dataframe = pd.DataFrame(X_train, columns=iris_dataset.feature_names) 
grr = pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15), marker='o', 
hist_kwds={'bins': 20}, s=60, alpha=.8, cmap=mglearn.cm3) 

嘗試做smtng像grr.plot(),沒有錯誤,但圖形沒有出現..誰知道爲什麼嗎?

回答

2

最好是使用matplotlib.pyplot的地塊

這增加了進口

import matplotlib.pyplot as plt 
在文件的最底部

然後

plt.show() 

您可以強制pandas做無需導入matplotlib但您在那裏所做的只是找到matplotlib已導入pandas,並調用相同的show函數。