当前位置: 首页>>代码示例>>Python>>正文


Python Earth.score方法代码示例

本文整理汇总了Python中pyearth.Earth.score方法的典型用法代码示例。如果您正苦于以下问题:Python Earth.score方法的具体用法?Python Earth.score怎么用?Python Earth.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyearth.Earth的用法示例。


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

示例1: test_sample_weight

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import score [as 别名]
def test_sample_weight():
    group = numpy.random.binomial(1, .5, size=1000) == 1
    sample_weight = 1 / (group * 100 + 1.0)
    x = numpy.random.uniform(-10, 10, size=1000)
    y = numpy.abs(x)
    y[group] = numpy.abs(x[group] - 5)
    y += numpy.random.normal(0, 1, size=1000)
    model = Earth().fit(x[:, numpy.newaxis], y, sample_weight=sample_weight)
    
    # Check that the model fits better for the more heavily weighted group
    assert_true(model.score(x[group], y[group]) < model.score(
        x[numpy.logical_not(group)], y[numpy.logical_not(group)]))
    
    # Make sure that the score function gives the same answer as the trace
    pruning_trace = model.pruning_trace()
    rsq_trace = pruning_trace.rsq(model.pruning_trace().get_selected())
    assert_almost_equal(model.score(x, y, sample_weight=sample_weight),
                        rsq_trace)
开发者ID:RPGOne,项目名称:han-solo,代码行数:20,代码来源:test_earth.py

示例2: test_missing_data

# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import score [as 别名]
def test_missing_data():
    earth = Earth(allow_missing=True, **default_params)
    missing_ = numpy.random.binomial(1, .05, X.shape).astype(bool)
    X_ = X.copy()
    X_[missing_] = None
    earth.fit(X_, y)
    res = str(earth.score(X_, y))
    filename = os.path.join(os.path.dirname(__file__),
                            'earth_regress_missing_data.txt')
#     with open(filename, 'w') as fl:
#         fl.write(res)
    with open(filename, 'r') as fl:
        prev = fl.read()
    assert_true(abs(float(res) - float(prev)) < .03)
开发者ID:RPGOne,项目名称:han-solo,代码行数:16,代码来源:test_earth.py


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