Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure 2.38 - UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored #168

Open
Jcolinese opened this issue Nov 16, 2022 · 6 comments

Comments

@Jcolinese
Copy link

in chapter 2
the In[76]
does not produce a graph - and i get this Warning
UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored

@rolandlamar
Copy link

rolandlamar commented Nov 25, 2022

Am also working thru the scripts in chapter 2 using Jupyter Lab in Windows 11. Tried numerous various but couldn't solve the cmap problem so I rewrote it using scatter3D. This works:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d

X_new = np.hstack([X, X[:, 1:] ** 2])

ax = plt.figure().add_subplot(projection='3d')
ax.view_init(elev=-152, azim=-26)

mask = y == 0

ax.scatter3D(X_new[mask, 0], X_new[mask, 1], X_new[mask, 2], c='b', s=60, edgecolor='k')
ax.scatter3D(X_new[~mask, 0], X_new[~mask, 1], X_new[~mask, 2], c='r', marker='^', s=60, edgecolor='k')
ax.set_xlabel("feature0")
ax.set_ylabel("feature1")
ax.set_zlabel("feature1 ** 2")
plt.show()

Script [77] has the same problem. If you run these sequentially in Jupyter do not need the first three lines. This works:

linear_svm_3d = LinearSVC().fit(X_new, y)
coef, intercept = linear_svm_3d.coef_.ravel(), linear_svm_3d.intercept_

ax = plt.figure().add_subplot(projection='3d')
ax.view_init(elev=-152, azim=-26)
xx = np.linspace(X_new[:, 0].min() - 2, X_new[:, 0].max() + 2, 50)
yy = np.linspace(X_new[:, 1].min() - 2, X_new[:, 1].max() + 2, 50)

XX, YY = np.meshgrid(xx, yy)
ZZ = (coef[0] * XX + coef[1] * YY + intercept) / -coef[2]
ax.plot_surface(XX, YY, ZZ, rstride=8, cstride=8, alpha=0.3)
ax.scatter3D(X_new[mask, 0], X_new[mask, 1], X_new[mask, 2], c='b', s=60, edgecolor='k')
ax.scatter3D(X_new[~mask, 0], X_new[~mask, 1], X_new[~mask, 2], c='r', marker='^', s=60, edgecolor='k')

ax.set_xlabel("feature0")
ax.set_ylabel("feature1")
ax.set_zlabel("feature1 ** 2")

@Jcolinese
Copy link
Author

Legend thankyou

@Arnold815
Copy link

thx for the solution

@wanghedy
Copy link

wanghedy commented Jan 7, 2023 via email

1 similar comment
@wanghedy
Copy link

wanghedy commented Jun 30, 2023 via email

@Irvenlikcrea
Copy link

you, my friend, hero!
thanks for the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants