introduction_to_ml_with_python
introduction_to_ml_with_python copied to clipboard
Figure 2.38 - UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored
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
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")
Legend thankyou
thx for the solution
您的邮件已收到,我将会尽快处理,谢谢。王宇凝
您的邮件已收到,我将会尽快处理,谢谢。王宇凝
you, my friend, hero! thanks for the solution.