2

Working through following the Machine Learning Tutorial:

http://machinelearningmastery.com/machine-learning-in-python-step-by-step/

Specifically, Section 4.2. Unfortunately, my code is throwing an error

NameError: name 'scatter_matrix' is not defined

Here is my code:

import pandas
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt

url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
dataset = pandas.read_csv(url, names=names)
scatter_matrix(dataset)
plt.show()

There's at least one Stack Overflow question on scatter_matrix, but I haven't able to figure out what's missing.

Pandas scatter_matrix - plot categorical variables

HMLDude
  • 1,547
  • 7
  • 27
  • 47

2 Answers2

3

You will have to import it like this:

from pandas.plotting import scatter_matrix
Jan Trienes
  • 2,501
  • 1
  • 16
  • 28
0

Cause you've imported the Pandas. You could use it like below:

pd.scatter_matrix(dataset)

However, pandas.scatter_matrix() is deprecated. use pandas.plotting.scatter_matrix() instead

BayarBH
  • 41
  • 10