- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Python2.7。这是 Udacity 的 Intro to Machine Learning 类(class)中的一个功能。调用该函数时,会显示一个图。但是,假设也显示了彩色区域,但未显示。
当我运行调用此函数的脚本时,图形会打开。当我关闭图形时,我看到以下消息:
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'
cm
是
matplotlib
的一个属性来自
matplotlib cm .于是,我改了
pl
'plt'。这消除了错误消息,但彩色区域仍然没有出现在绘图中。因此,我不太相信这是正确的。
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
# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, m_max]x[y_min, y_max].
h = .01 # step size in the mesh
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()])
# Put the result into a color plot
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)
# Plot also the test points
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")
最佳答案
替换 cmap=pl.cm.seismic
与 cmap=plt.cm.seismic
替换 plt.savefig("your_image.png")
和
figure = plt.gcf()
plt.show()
plt.draw()
figure.savefig("your_image.png", dpi=100)
关于python-2.7 - 属性错误 : 'module' object has no attribute 'cm' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35050062/
当我在 alfresce 中跟踪代码时,我在 node-header.get.html.ftl 中发现了以下代码 ...... 我
我正在尝试重新创建我见过的服装测量图表,但使用纯 Javascript。我无法弄清楚如何获取 innerhtml 中的数值并将其乘以/除以 * 2.54。另外,我想在数字末尾添加“cm”或“in”来表
我尝试从网站 https://plot.ly/scikit-learn/plot-kmeans-silhouette-analysis/ 运行代码.当我运行时发现 matplotlib 模块已经没有光
有人知道这是浏览器、Windows 语言还是一般问题吗? 我在我的计算机上安装了一种名为“阿拉伯语(沙特阿拉伯)阿拉伯语 (101) 键盘”的第二语言。 如果我输入像“test 3cm test”这样
Name Team Number Position Age Height Weight College Salary
我一直在按照给定的快速入门指南安装 kuali 类(class)管理系统 HERE . 我已成功完成所有操作,但无法在 tomcat 中部署应用程序。 我以前从未真正使用过 tomcat,所以任何人都
我在我的 CSS 媒体查询中使用厘米来使我的模板具有响应性,而现在我们的智能手机具有非常高的分辨率,这使得像素过滤器变得困难。我的问题是,为什么所有网站都不使用 CM 来使响应变得更加简单和实用?使用
plt.cm中cm全称表示colormap paired表示两个两个相近色彩输出,比如浅蓝、深蓝 ;浅红、深红;浅绿,深绿这种。 补充:【python】plt.cm.Spectral,颜色分配
using System.Collections; using System.Collections.Generic; using UnityEngine; using Cinemachine; us
我们有一个 Web 应用程序,其中包含系统运算符(operator)可以更改的一堆内容(例如新闻和事件)。有时我们会发布软件的新版本。该软件被标记并存储在颠覆中。但是,对于如何最好地控制可能独立更改的
我已经阅读了 http://webdev.apl.jhu.edu/~jcs/ejava-javaee/coursedocs/605-784-site/docs/content/html/devenv-
我正在尝试从 CM 源为我的设备构建自定义 rom。我正在按照本指南进行构建: https://wiki.cyanogenmod.org/w/Build_for_quark 我正在使用此命令来同步源。
我看过 WWDC 2015 Session 705 上的视频,发现 Core Motion API 很有趣。我正在制作一个应用程序,需要随着后台运动事件状态的变化而更新。例如,当用户走进汽车并开始驾驶
我想在具有已定义宽度和高度的 WebView 中显示图像。 当我将 html 设置为:显示时:高度永远不会达到 100 厘米或任何我选择的高度。 我尝试使用视口(viewport)和比例,但未能以正确
我注意到 Chrome 浏览器中的元素大小存在问题。 我写了一个简单的代码: TEXT TEXT TEXT TEXT
我公司使用CM Synergy作为代码版本控制工具,可能是我自己的问题,我不能很好地使用这个工具。但以我自己的经验来看,Hg、Git 或 SVN 对我来说非常有用。有什么方法可以将开源控件存档转换为
我正在尝试部署使用 Dash 开发的应用程序,该应用程序使用一些 matplotlib 函数。当我在本地运行应用程序时,它运行顺利,一切正常,但是,当我使用相同的代码(我正在使用 heroku 部署)
我有 ?(New System.Windows.LengthConverter()).ConvertFrom("1cm") 37.795275590551178 {Double} Double
我正在我正在构建的网站上使用营销事件表单。有多种形式遵循相同的结构(见下文)并使用相同的类名。 我使用 AJAX 将表单发布到 Campaign Monitor,如果返回错误消息,还添加类,如果正确则
OCaml 对编译后的文件有多种扩展名:*.a, *.cma, *.cmi, *.cmx 、*.cmxa、*.cmxs(也许这不是详尽的列表)。它们是什么,在什么情况下我需要它们? 如果我有一个库,我
我是一名优秀的程序员,十分优秀!