- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试指定进入我的 H2o.Frame 的列类型。在每种情况下,我都尝试过几种不同的方法。单元测试如下。除了最后两个,它们都失败了,但最后两个只能工作,因为我已经将 99.0 更改为 99.9。为什么我不能告诉它 99.0 仍然是一个 float 而不是一个整数?
import unittest
from unittest import TestCase
import h2o
class TestInputtingTypes(TestCase):
def setUp(self):
h2o.init()
def test_h2o_1(self):
data =[(1,'one', 9),(9,'two',3), (8,'three', 99.0)]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'real'}
frame = h2o.H2OFrame(data, column_types=given_types)
actual_types = frame.types
self.assertDictEqual(given_types, actual_types)
def test_h2o_2(self):
data =[(1,'one', 9),(9,'two',3), (8,'three', 99.0)]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'real'}
names = ['C1', 'C2', 'C3']
frame = h2o.H2OFrame(data, column_types=given_types, column_names=names)
actual_types = frame.types
self.assertDictEqual(given_types, actual_types)
def test_h2o_3(self):
data =[{'C1': 1, 'C2': 'one', 'C3': 9},
{'C1': 9, 'C2': 'two', 'C3': 3},
{'C1': 8, 'C2': 'three', 'C3': 99.0}]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'real'}
names = ['C1', 'C2', 'C3']
frame = h2o.H2OFrame(data, column_types=given_types, column_names=names)
actual_types = frame.types
self.assertDictEqual(given_types, actual_types)
def test_h2o_4(self):
data =[{'C1': 1, 'C2': 'one', 'C3': 9},
{'C1': 9, 'C2': 'two', 'C3': 3},
{'C1': 8, 'C2': 'three', 'C3': 99.0}]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'real'}
given_types_input = {'C1': 'numeric', 'C2': 'string', 'C3': 'float'}
names = ['C1', 'C2', 'C3']
frame = h2o.H2OFrame(data, column_types=given_types_input, column_names=names)
actual_types = frame.types
self.assertDictEqual(given_types, actual_types)
def test_h2o_5(self):
data =[(1,'one', 9),(9,'two',3), (8,'three', 99.0)]
given_types = ['int', 'string', 'real']
names = ['C1', 'C2', 'C3']
frame = h2o.H2OFrame(data, column_types=given_types, column_names=names)
actual_types = frame.types
self.assertDictEqual(given_types, actual_types)
def test_h2o_6_this_one_passes_because_has_nonzero_decimals(self):
data =[(1,'one', 9),(9,'two',3), (8,'three', 99.9)]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'real'}
given_types_input = ['int', 'string', 'real']
names = ['C1', 'C2', 'C3']
frame = h2o.H2OFrame(data, column_types=given_types_input, column_names=names)
actual_types = frame.types
self.assertDictEqual(given_types, actual_types)
def test_h2o_7_this_one_passes_because_has_nonzero_decimals(self):
data =[(1,'one', 9),(9,'two',3), (8,'three', 99.9)]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'real'}
names = ['C1', 'C2', 'C3']
frame = h2o.H2OFrame(data)
actual_types = frame.types
self.assertDictEqual(given_types, actual_types)
if __name__ == "__main__" :
unittest.main()
最佳答案
问题是 int
不是您可以传递给 h2o col_types
参数的选项,您需要传递 numeric
。
如果您将 numeric
传递给您的 real 和 int 值,那应该可以解决您的问题 - 尽管整数将被转换为 float 。为了 使用 H2O 整数,因此可以将它们映射到分类(使用 .asfactor()
)
在 H2O 中允许以下类型
“未知”- 这将强制将该列解析为所有 NA
“uuid” - 列中的值必须是真实的 UUID,否则将被解析为 NA
“string” - 强制将列解析为字符串
“数字”- 强制将列解析为数字。 H2O 将以最佳方式处理数字数据的压缩。
“枚举”- 强制将列解析为分类列。
“time” - 强制将列解析为时间列。 H2O 将尝试解析以下日期时间格式列表:(date) “yyyy-MM-dd”, “yyyy MM dd”, “dd-MMM-yy”, “dd MMM yy”, (time) “HH: mm:ss”, “HH:mm:ss:SSS”, “HH:mm:ss:SSSnnnnnn”, “HH.mm.ss” “HH.mm.ss.SSS”, “HH.mm.ss.SSSnnnnnn” ”。时间也可以包含“AM”或“PM”。
您可以在文档中查看更多详细信息:http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/h2o.html?highlight=import_file#h2o.import_file
关于python - 为什么 H2oFrame 忽略我的输入列类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45085994/
我尝试在安装了多类型 MFC 库的 visual studio 2015 MFC 上运行以前编写的 MFC c++ 代码。 但是,我这里仍然有 12 个关于缺少函数的错误: IntelliSense:
我正在学习 OOP 并且有疑问。假设我有一个包含 ClassB.h 的文件 ClassA.h,并且在某些时候我的 ClassB.h 需要包含 ClassA .h。 这会产生一个错误,我想我明白为什么会
我开始使用 CUDA 进行编程,在一些示例中我找到了包含文件 cuda.h、cuda_runtime.h 和 cuda_runtime_api.h 包含在代码中。有人可以向我解释一下这些文件之间的区别
我有一些生成正则表达式的代码。那么下面的表达式实际上是: ^(?:\s*((exclude|include|hide|show|protect|risk|dir-merge|merge)),\s*((
我一直在查看一些源代码,以更好地了解我们使用的这款游戏的核心,并编写更可靠、更快速的插件。然后我发现了这段奇怪的代码...... public void setMaxH(double amount)
通常我们会使用标准类型作为 std::unordered_map 的键和值.但现在我需要自定义我自己的键和值类。 键类在block_cache_key.h 中定义如下: #ifndef BLOCK_C
例如,我想要两个头文件,它们可以依赖于另一个头文件中的函数。 //Header1.h file #include Header2.h void h1(){ //... func1(); } v
我正在研究来自 Sedgewick 的 Shell 排序 Algorithms in C part 1-4在第 172 页。 我使用 size (数组的长度),而不是 l和 r (开始和结束);所以我
我在 macOS BigSur 上通过 VMWare 使用 Ubuntu 20.04.2 LTS。我安装了最新版本的 tcl、tcl-dev、tk 和 tk-dev - 版本 8.6。我想编译 Arc
我用我的 glu 和 gl 头文件构建了一个 OpenGL 程序,默认包含在 windows 7 专业版中。现在,我买了一本描述 OpenGL 游戏开发的书。这本书的作者说,我必须在我的项目中包含 g
我想在 token 中保留特殊字符,同时仍对特殊字符进行 token 化。说我有话 "H&R Blocks" 我想将其标记为 "H", "R", "H&R", "Blocks" 我读了http://w
关于 hash 作为 trans 参数的另一个问题。在下面的代码中,简单地使用 hash 会给出不正确的结果,但是将其替换为 keys 和 values 会使其正确。怎么了? my @alph1 =
我已经编写了一个 C 程序,它获取屏幕像素的 RGB 值 (0-255),并知道其位置 (x,y)。它可以在 Linux 中运行,但是当我尝试在 Visual Studio (Windows) 中编译
我已经使用 Windows 7 专业版中默认包含的 glu 和 gl 头文件构建了一个 OpenGL 程序。现在,我买了一本描述 OpenGL 游戏开发的书。这本书的作者说,我必须将glew head
#include using namespace std; #include //#include int main() { initscr();
h:messages h:form 内的组件还显示与外部组件相关的消息。 如何限制它只显示与包含 h:form 内的组件相关的消息? 我不喜欢用单独的h:message来使我的代码膨胀。每个输入组件的
我下载了示例代码和 cpp 文件,其中包含 list.h、queue.h 和 vector.h 等头文件,如果我尝试构建,我会收到“ fatal error :没有这样的文件或目录编译终止”我想我应该
我有一个编译成功的桌面项目,但是在我向项目添加新配置以支持 Windows Mobile 平台后,我收到以下错误: error C2146: syntax error : missing ';' be
有很多关于这个错误的帖子,但我无法解决它,我希望你能拿出解决方案。我在 Ubuntu 机器上。 ~/graphmap2$ 在这个文件夹中,我下载了 zlib。可以看图 经过一番谷歌搜索后,我还注意到没
是否可以在 Visual C++ 中使用以下 header : 图.h dos.h bios.h 最佳答案 据我所知,无法在 Visual C++ 中使用它, 与此同时,我希望您关注 Open Wat
我是一名优秀的程序员,十分优秀!