本文整理汇总了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)
示例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)