Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么H2oFrame会忽略我的输入列类型?_Python_H2o - Fatal编程技术网

Python 为什么H2oFrame会忽略我的输入列类型?

Python 为什么H2oFrame会忽略我的输入列类型?,python,h2o,Python,H2o,我试图指定进入H2o.Frame的列类型。我试过几种不同的方法,在每种情况下都是如此。单元测试如下。除了最后两个,它们都失败了,但最后两个都有效,因为我将99.0改为99.9。为什么我不能告诉它99.0仍然是一个浮点而不是整数 import unittest from unittest import TestCase import h2o class TestInputtingTypes(TestCase): def setUp(self): h2o.init()

我试图指定进入H2o.Frame的列类型。我试过几种不同的方法,在每种情况下都是如此。单元测试如下。除了最后两个,它们都失败了,但最后两个都有效,因为我将99.0改为99.9。为什么我不能告诉它99.0仍然是一个浮点而不是整数

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\u types
参数的选项,您需要传递
numeric

如果传递实数和int值的
numeric
,应该可以解决问题-尽管整数将转换为浮点。对于 使用H2O整数可以将它们映射到Category(使用
.asfactor()

在H2O中,允许以下类型

“未知”-这将强制将列解析为所有NA

“uuid”-列中的值必须为真uuid或将被解析为NA

“string”-强制将列解析为字符串

“numeric”-强制将列解析为数字。H2O将以最佳方式处理数字数据的压缩

“enum”-强制将列解析为分类列

“时间”-强制将列解析为时间列。H2O将尝试解析以下日期时间格式列表:(日期)“yyyy-MM-dd”、“yyyy-MM-dd”、“dd-MMM-yy”、“dd-MMM-yy”,(时间)“HH:MM:ss”、“HH:MM:ss:SSS”、“HH:MM:ss:sssnnnn”、“HH.MM.ss”“HH.MM.ss.SSS”、“HH.MM.ss.sssnnnn”。时间也可以包含“上午”或“下午”


您可以在文档中看到更多详细信息:

问题在于
int
不是一个可以传递到h2o
col\u types
参数的选项,您需要传递
numeric

如果传递实数和int值的
numeric
,应该可以解决问题-尽管整数将转换为浮点。对于 使用H2O整数可以将它们映射到Category(使用
.asfactor()

在H2O中,允许以下类型

“未知”-这将强制将列解析为所有NA

“uuid”-列中的值必须为真uuid或将被解析为NA

“string”-强制将列解析为字符串

“numeric”-强制将列解析为数字。H2O将以最佳方式处理数字数据的压缩

“enum”-强制将列解析为分类列

“时间”-强制将列解析为时间列。H2O将尝试解析以下日期时间格式列表:(日期)“yyyy-MM-dd”、“yyyy-MM-dd”、“dd-MMM-yy”、“dd-MMM-yy”,(时间)“HH:MM:ss”、“HH:MM:ss:SSS”、“HH:MM:ss:sssnnnn”、“HH.MM.ss”“HH.MM.ss.SSS”、“HH.MM.ss.sssnnnn”。时间也可以包含“上午”或“下午”


您可以在文档中看到更多详细信息:

在H2O中,数据存储是通过H2O优化的,因此如果您有一个可以用更少字节存储的列(例如“int”),那么H2O将以这种方式存储它,即使您试图强制它使用“real”(或float)类型

对于指定列类型,H2O有自己的词汇表来描述类型(在Lauren的中有详细说明),但您会看到,当您为第三列指定“numeric”时,它将以int结尾

data =[(1,'one', 9),(9,'two',3), (8,'three', 99.0)]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'numeric'}
frame = h2o.H2OFrame(data, column_types=given_types)
actual_types = frame.types
结果:

In [39]: actual_types
Out[39]: {u'C1': u'int', u'C2': u'string', u'C3': u'int'}

In [40]: given_types
Out[40]: {'C1': 'int', 'C2': 'string', 'C3': 'numeric'}

在H2O中,数据存储是通过H2O优化的,因此如果您有一个可以用更少字节存储的列(例如“int”),那么H2O将以这种方式存储它,即使您试图强制它使用“real”(或float)类型

对于指定列类型,H2O有自己的词汇表来描述类型(在Lauren的中有详细说明),但您会看到,当您为第三列指定“numeric”时,它将以int结尾

data =[(1,'one', 9),(9,'two',3), (8,'three', 99.0)]
given_types = {'C1': 'int', 'C2': 'string', 'C3': 'numeric'}
frame = h2o.H2OFrame(data, column_types=given_types)
actual_types = frame.types
结果:

In [39]: actual_types
Out[39]: {u'C1': u'int', u'C2': u'string', u'C3': u'int'}

In [40]: given_types
Out[40]: {'C1': 'int', 'C2': 'string', 'C3': 'numeric'}

将文件保存到csv后,使用传递的参数
col\u types
而不是
h2o.H2OFrame()
尝试使用
h2o.
。这就解决了我的问题。

只要尝试使用
h2o。
()
将文件保存到csv后,使用传递的参数
列类型,而不是
h2o.H2OFrame()
。这解决了我的问题。

输入“数值”而不是“真实”将无法解决问题。如果在可转换为[9,3,99.0]等整数的列中传入“numeric”,则
frame.types
仍将显示“int”作为类型。传入“numeric”而不是“real”不会解决问题。如果在可以转换为[9,3,99.0]等整数的列中传入“numeric”,则
frame.types
仍将显示“int”作为类型。