• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tools.categorical函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中statsmodels.tools.tools.categorical函数的典型用法代码示例。如果您正苦于以下问题:Python categorical函数的具体用法?Python categorical怎么用?Python categorical使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了categorical函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_dummy_sparse

    def test_dummy_sparse(self):
        data = self.data
        self.grouping.dummy_sparse()
        expected = categorical(data.index.get_level_values(0).values,
                               drop=True)
        np.testing.assert_equal(self.grouping._dummies.toarray(), expected)

        if len(self.grouping.group_names) > 1:
            self.grouping.dummy_sparse(level=1)
            expected = categorical(data.index.get_level_values(1).values,
                    drop=True)
            np.testing.assert_equal(self.grouping._dummies.toarray(),
                                    expected)
开发者ID:0ceangypsy,项目名称:statsmodels,代码行数:13,代码来源:test_grouputils.py


示例2: test_issue302

def test_issue302():
    arr = np.rec.fromrecords([[10, 12], [11, 13]], names=['group', 'whatever'])
    actual = tools.categorical(arr, col=['group'])
    expected = np.rec.array([(10, 12, 1.0, 0.0), (11, 13, 0.0, 1.0)],
        dtype=[('group', int), ('whatever', int), ('group_10', float),
               ('group_11', float)])
    assert_array_equal(actual, expected)
开发者ID:bfcondon,项目名称:statsmodels,代码行数:7,代码来源:test_tools.py


示例3: test_rec_issue302

def test_rec_issue302():
    arr = np.rec.fromrecords([[10], [11]], names="group")
    actual = tools.categorical(arr)
    expected = np.rec.array(
        [(10, 1.0, 0.0), (11, 0.0, 1.0)], dtype=[("group", int), ("group_10", float), ("group_11", float)]
    )
    assert_array_equal(actual, expected)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:7,代码来源:test_tools.py


示例4: test_const_indicator

def test_const_indicator():
    np.random.seed(12345)
    X = np.random.randint(0, 3, size=30)
    X = categorical(X, drop=True)
    y = np.dot(X, [1., 2., 3.]) + np.random.normal(size=30)
    modc = OLS(y, add_constant(X[:,1:], prepend=True)).fit()
    mod = OLS(y, X, hasconst=True).fit()
    assert_almost_equal(modc.rsquared, mod.rsquared, 12)
开发者ID:NanoResearch,项目名称:statsmodels,代码行数:8,代码来源:test_regression.py


示例5: test_issue302

def test_issue302():
    arr = np.rec.fromrecords([[10, 12], [11, 13]], names=["group", "whatever"])
    actual = tools.categorical(arr, col=["group"])
    expected = np.rec.array(
        [(10, 12, 1.0, 0.0), (11, 13, 0.0, 1.0)],
        dtype=[("group", int), ("whatever", int), ("group_10", float), ("group_11", float)],
    )
    assert_array_equal(actual, expected)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:8,代码来源:test_tools.py


示例6: test_fvalue_const_only

def test_fvalue_const_only():
    np.random.seed(12345)
    x = np.random.randint(0, 3, size=30)
    x = categorical(x, drop=True)
    x[:, 0] = 1
    y = np.dot(x, [1., 2., 3.]) + np.random.normal(size=30)
    res = OLS(y, x, hasconst=True).fit(cov_type='HC1')
    assert not np.isnan(res.fvalue)
开发者ID:statsmodels,项目名称:statsmodels,代码行数:8,代码来源:test_regression.py


示例7: test_const_indicator

def test_const_indicator():
    np.random.seed(12345)
    X = np.random.randint(0, 3, size=30)
    X = categorical(X, drop=True)
    y = np.dot(X, [1., 2., 3.]) + np.random.normal(size=30)
    resc = OLS(y, add_constant(X[:, 1:], prepend=True)).fit()
    res = OLS(y, X, hasconst=True).fit()
    assert_almost_equal(resc.rsquared, res.rsquared, 12)
    assert res.model.data.k_constant == 1
    assert resc.model.data.k_constant == 1
开发者ID:statsmodels,项目名称:statsmodels,代码行数:10,代码来源:test_regression.py


示例8: test_array2d_drop

 def test_array2d_drop(self):
     des = np.column_stack((self.des, self.instr, self.des))
     des = tools.categorical(des, col=2, drop=True)
     assert_array_equal(des[:, -5:], self.dummy)
     assert_equal(des.shape[1], 9)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:5,代码来源:test_tools.py


示例9: test_structarray1d_drop

 def test_structarray1d_drop(self):
     instr = self.structdes["str_instr"].view(dtype=[("var1", "a10")])
     dum = tools.categorical(instr, drop=True)
     test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names]))
     assert_array_equal(test_dum, self.dummy)
     assert_equal(len(dum.dtype.names), 5)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:6,代码来源:test_tools.py


示例10: test_structarray2d_drop

 def test_structarray2d_drop(self):
     des = tools.categorical(self.structdes, col="str_instr", drop=True)
     test_des = np.column_stack(([des[_] for _ in des.dtype.names[-5:]]))
     assert_array_equal(test_des, self.dummy)
     assert_equal(len(des.dtype.names), 8)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:5,代码来源:test_tools.py


示例11: test_structarray2dint

 def test_structarray2dint(self):
     des = tools.categorical(self.structdes, col=3)
     test_des = np.column_stack(([des[_] for _ in des.dtype.names[-5:]]))
     assert_array_equal(test_des, self.dummy)
     assert_equal(len(des.dtype.names), 9)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:5,代码来源:test_tools.py


示例12: test_recarray1d

 def test_recarray1d(self):
     instr = self.structdes["str_instr"].view(np.recarray)
     dum = tools.categorical(instr)
     test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names[-5:]]))
     assert_array_equal(test_dum, self.dummy)
     assert_equal(len(dum.dtype.names), 6)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:6,代码来源:test_tools.py


示例13: test_recarray2d

 def test_recarray2d(self):
     des = tools.categorical(self.recdes, col="str_instr")
     # better way to do this?
     test_des = np.column_stack(([des[_] for _ in des.dtype.names[-5:]]))
     assert_array_equal(test_des, self.dummy)
     assert_equal(len(des.dtype.names), 9)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:6,代码来源:test_tools.py


示例14: test_array1d_drop

 def test_array1d_drop(self):
     des = tools.categorical(self.string_var, drop=True)
     assert_array_equal(des, self.dummy)
     assert_equal(des.shape[1], 5)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:4,代码来源:test_tools.py


示例15: test_structarray1d

 def test_structarray1d(self):
     instr = self.structdes["instrument"].view(dtype=[("var1", "f4")])
     dum = tools.categorical(instr)
     test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names[-5:]]))
     assert_array_equal(test_dum, self.dummy)
     assert_equal(len(dum.dtype.names), 6)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:6,代码来源:test_tools.py


示例16: test_arraylike2d_drop

 def test_arraylike2d_drop(self):
     des = tools.categorical(self.structdes.tolist(), col=2, drop=True)
     test_des = des[:,-5:]
     assert_array_equal(test_des, self.dummy)
     assert_equal(des.shape[1], 8)
开发者ID:bashtage,项目名称:statsmodels,代码行数:5,代码来源:test_tools.py


示例17: test_array1d

 def test_array1d(self):
     des = tools.categorical(self.instr)
     assert_array_equal(des[:, -5:], self.dummy)
     assert_equal(des.shape[1], 6)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:4,代码来源:test_tools.py


示例18: test_arraylike1d_drop

 def test_arraylike1d_drop(self):
     instr = self.structdes['instrument'].tolist()
     dum = tools.categorical(instr, drop=True)
     assert_array_equal(dum, self.dummy)
     assert_equal(dum.shape[1], 5)
开发者ID:bashtage,项目名称:statsmodels,代码行数:5,代码来源:test_tools.py


示例19: test_array2d

 def test_array2d(self):
     des1 = np.column_stack((self.des, self.instr, self.des))
     des = tools.categorical(des1, col=2)
     assert_array_equal(des[:,-5:], self.dummy)
     assert_equal(des.shape[1],10)
开发者ID:bfcondon,项目名称:statsmodels,代码行数:5,代码来源:test_tools.py


示例20: test_recarray1d_drop

 def test_recarray1d_drop(self):
     instr = self.structdes["instrument"].view(np.recarray)
     dum = tools.categorical(instr, drop=True)
     test_dum = np.column_stack(([dum[_] for _ in dum.dtype.names]))
     assert_array_equal(test_dum, self.dummy)
     assert_equal(len(dum.dtype.names), 5)
开发者ID:nsolcampbell,项目名称:statsmodels,代码行数:6,代码来源:test_tools.py



注:本文中的statsmodels.tools.tools.categorical函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.chain_dot函数代码示例发布时间:2022-05-27
下一篇:
Python tools.add_constant函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap