1

Could you please let me know what is wrong with the code-

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') 

I am expecting some sort of matrix plot like this. However, it is just showing one histogram. I am not sure what is going wrong.

Additionally, is there any easy way to add legend on this type of matrix plot?

I am recently trying to switch from MATLAB to python; so, I am new on python.

Update: Apparently plotting problem is solved by modifying just one line-

temp = pd.DataFrame(data=trainData,columns=features,dtype=float)
user3862410
  • 171
  • 1
  • 6
  • I'd better make your example a minimal example that reproduces the problem. I'm personally not investing the time to learn all your code to see what's wrong. – Marc Garcia Sep 18 '19 at 22:05

0 Answers0