I am using Python2.7. This is a feature of the Udacity Intro to Machine Learning course. When a function is called, a graph is displayed. However, suppose that colored areas are also shown, and they are not shown.
When I run a script that calls this function, a digit opens. When I close the shape, I see this message:
Traceback (most recent call last):
File "your_algorithm.py", line 45, in <module>
prettyPicture(clf, features_test, labels_test)
File "e:\Projects\Udacity\Intro to Machine Learning\ud120-projects\choose_your_own\class_vis.py", line 22, in prettyPicture
plt.pcolormesh(xx, yy, Z, cmap=pl.cm.seismic)
AttributeError: 'module' object has no attribute 'cm'
It seemed to me that cmis an attribute matplotlibfrom matplotlib cm . So I changed plto 'plt`. This eliminates the error message, but the colored areas are still not displayed in the plot. Thus, I am less convinced that this is correct.
Why are color areas not displayed?
Here is the prettyPicture function code:
import numpy as np
import matplotlib.pyplot as plt
import pylab as pl
def prettyPicture(clf, X_test, y_test):
x_min = 0.0; x_max = 1.0
y_min = 0.0; y_max = 1.0
h = .01
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.pcolormesh(xx, yy, Z, cmap=pl.cm.seismic)
grade_sig = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==0]
bumpy_sig = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==0]
grade_bkg = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==1]
bumpy_bkg = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==1]
plt.scatter(grade_sig, bumpy_sig, color = "b", label="fast")
plt.scatter(grade_bkg, bumpy_bkg, color = "r", label="slow")
plt.legend()
plt.xlabel("bumpiness")
plt.ylabel("grade")
plt.savefig("test.png")