1

您能否让我知道代码有什么问题-

import pandas as pd
import numpy as np
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" # load dataset into Pandas DataFrame
df = pd.read_csv(url, names=['sepal length','sepal width','petal length','petal width','target'])
data = df.values[:,0:4]
label = df.target.values
features = df.columns.values[0:4]

#create train Data
trainData = np.delete(data, list(range(0, data.shape[0], 3)), axis=0)
trainLabel = np.delete(label, list(range(0, label.shape[0], 3)), axis=0)

#create test Data
testData = data[0::3,:]
testLabel = label[0::3]

#visualize train Data
temp = pd.DataFrame(data=trainData,columns=features)
temp["target"] = trainLabel
color_palette = {1: "#0392cf",
                 2: "#7bc043",
                 3: "#ee4035"}
lab = list(np.unique(trainLabel))
labNum = temp['target'].apply(lab.index)
colors = labNum.map(lambda x: color_palette.get(x + 1))
temp["target"] = list(labNum)
ax = pd.plotting.scatter_matrix(temp, color=colors, alpha=0.6, figsize=(10, 10), diagonal='hist') 

我期待某种像这样的矩阵图。但是,它只显示一个直方图。我不确定出了什么问题。

此外,有没有什么简单的方法可以在这种类型的矩阵图上添加图例?

我最近试图从 MATLAB 切换到 python;所以,我是python的新手。

更新:显然,只需修改一行即可解决绘图问题-

temp = pd.DataFrame(data=trainData,columns=features,dtype=float)
4

0 回答 0