本文整理汇总了Python中pyearth.Earth.summary方法的典型用法代码示例。如果您正苦于以下问题:Python Earth.summary方法的具体用法?Python Earth.summary怎么用?Python Earth.summary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyearth.Earth
的用法示例。
在下文中一共展示了Earth.summary方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fast
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
def test_fast():
earth = Earth(max_terms=10,
max_degree=5,
**default_params)
earth.fit(X, y)
normal_summary = earth.summary()
earth = Earth(use_fast=True,
max_terms=10,
max_degree=5,
fast_K=10,
fast_h=1,
**default_params)
earth.fit(X, y)
fast_summary = earth.summary()
assert_equal(normal_summary, fast_summary)
示例2: test_pathological_cases
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
def test_pathological_cases():
import pandas
directory = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'pathological_data')
cases = {'issue_44': {},
'issue_50': {'penalty': 0.5,
'minspan': 1,
'allow_linear': False,
'endspan': 1,
'check_every': 1,
'sample_weight': 'issue_50_weight.csv'}}
for case, settings in cases.iteritems():
data = pandas.read_csv(os.path.join(directory, case + '.csv'))
y = data['y']
del data['y']
X = data
if 'sample_weight' in settings:
filename = os.path.join(directory, settings['sample_weight'])
sample_weight = pandas.read_csv(filename)['sample_weight']
del settings['sample_weight']
else:
sample_weight = None
model = Earth(**settings)
model.fit(X, y, sample_weight=sample_weight)
with open(os.path.join(directory, case + '.txt'), 'r') as infile:
correct = infile.read()
assert_equal(model.summary(), correct)
示例3: test_smooth
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
def test_smooth():
model = Earth(penalty=1, smooth=True)
model.fit(X, y)
res = str(model.trace()) + '\n' + model.summary()
filename = os.path.join(os.path.dirname(__file__),
'earth_regress_smooth.txt')
with open(filename, 'r') as fl:
prev = fl.read()
assert_equal(res, prev)
示例4: test_fit
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
def test_fit():
earth = Earth(**default_params)
earth.fit(X, y)
res = str(earth.trace()) + '\n' + earth.summary()
filename = os.path.join(os.path.dirname(__file__),
'earth_regress.txt')
with open(filename, 'r') as fl:
prev = fl.read()
assert_equal(res, prev)
示例5: test_linvars
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
def test_linvars():
earth = Earth(**default_params)
earth.fit(X, y, linvars=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
res = str(earth.trace()) + '\n' + earth.summary()
filename = os.path.join(os.path.dirname(__file__),
'earth_linvars_regress.txt')
# with open(filename, 'w') as fl:
# fl.write(res)
with open(filename, 'r') as fl:
prev = fl.read()
assert_equal(res, prev)
示例6: test_untrained
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
def test_untrained():
model = Earth(**default_params)
assert_raises(NotFittedError, model.predict, X)
assert_raises(NotFittedError, model.transform, X)
assert_raises(NotFittedError, model.predict_deriv, X)
assert_raises(NotFittedError, model.score, X)
# the following should be changed to raise NotFittedError
assert_equal(model.forward_trace(), None)
assert_equal(model.pruning_trace(), None)
assert_equal(model.summary(), "Untrained Earth Model")
示例7: test_untrained
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
def test_untrained():
# NotFittedError moved from utils.validation to exceptions
# some time after 0.17.1
try:
from sklearn.exceptions import NotFittedError
except ImportError:
from sklearn.utils.validation import NotFittedError
# Make sure calling methods that require a fitted Earth object
# raises the appropriate exception when using a not yet fitted
# Earth object
model = Earth(**default_params)
assert_raises(NotFittedError, model.predict, X)
assert_raises(NotFittedError, model.transform, X)
assert_raises(NotFittedError, model.predict_deriv, X)
assert_raises(NotFittedError, model.score, X)
# the following should be changed to raise NotFittedError
assert_equal(model.forward_trace(), None)
assert_equal(model.pruning_trace(), None)
assert_equal(model.summary(), "Untrained Earth Model")
示例8: Earth
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
np.random.seed(1)
m = 1000
n = 5
X = np.random.normal(size=(m,n))
# Make X[:,1] binary
X[:,1] = np.random.binomial(1,.5,size=m)
# The response is a linear function of the inputs
y = 2 * X[:,0] + 3 * X[:,1] + np.random.normal(size=m)
# Fit the earth model
model = Earth().fit(X, y)
# Print the model summary, showing linear terms
print model.summary()
# Plot for both values of X[:,1]
y_hat = model.predict(X)
plt.figure()
plt.plot(X[:,0], y, 'k.')
plt.plot(X[X[:,1] == 0, 0], y_hat[X[:,1] == 0], 'r.', label='$x_1 = 0$')
plt.plot(X[X[:,1] == 1, 0], y_hat[X[:,1] == 1], 'b.', label='$x_1 = 1$')
plt.legend(loc='best')
plt.xlabel('$x_0$')
plt.show()
示例9: DictVectorizer
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
from sklearn import preprocessing
from sklearn.feature_extraction import DictVectorizer
from pyearth import Earth
from matplotlib import pyplot
df = pd.read_excel('relay-foods.xlsx', sheetname='Purchase Data - Full Study')
df['OrderId'] = df['OrderId'].astype('category')
df['CommonId'] = df['CommonId'].astype('category')
df['OrderId'] = df['OrderId'].astype('category')
df['CommonId'] = df['CommonId'].astype('category')
df.dtypes
col_names = ['OrderDate', 'PickupDate']
df = df.drop(col_names, axis=1)
y = df['TotalCharges']
df_2 = df[['OrderId', 'UserId', 'PupId']]
#del df['OrderDate']
X = [dict(r.iteritems()) for _, r in df_2.iterrows()]
train_fea = DictVectorizer().fit_transform(X)
#Fit an Earth model
model = Earth()
model.fit(train_fea,y)
#Print the model
print(model.trace())
print(model.summary())
#Plot the model
y_hat = model.predict(X)
示例10: TestEarth
# 需要导入模块: from pyearth import Earth [as 别名]
# 或者: from pyearth.Earth import summary [as 别名]
class TestEarth(object):
def __init__(self):
numpy.random.seed(0)
self.basis = Basis(10)
constant = ConstantBasisFunction()
self.basis.append(constant)
bf1 = HingeBasisFunction(constant, 0.1, 10, 1, False, 'x1')
bf2 = HingeBasisFunction(constant, 0.1, 10, 1, True, 'x1')
bf3 = LinearBasisFunction(bf1, 2, 'x2')
self.basis.append(bf1)
self.basis.append(bf2)
self.basis.append(bf3)
self.X = numpy.random.normal(size=(100, 10))
self.B = numpy.empty(shape=(100, 4), dtype=numpy.float64)
self.basis.transform(self.X, self.B)
self.beta = numpy.random.normal(size=4)
self.y = numpy.empty(shape=100, dtype=numpy.float64)
self.y[:] = numpy.dot(
self.B, self.beta) + numpy.random.normal(size=100)
self.earth = Earth(penalty=1)
def test_get_params(self):
assert_equal(
Earth().get_params(), {'penalty': None, 'min_search_points': None,
'endspan_alpha': None, 'check_every': None,
'max_terms': None, 'max_degree': None,
'minspan_alpha': None, 'thresh': None,
'minspan': None, 'endspan': None,
'allow_linear': None, 'smooth': None})
assert_equal(
Earth(
max_degree=3).get_params(), {'penalty': None,
'min_search_points': None,
'endspan_alpha': None,
'check_every': None,
'max_terms': None, 'max_degree': 3,
'minspan_alpha': None,
'thresh': None, 'minspan': None,
'endspan': None,
'allow_linear': None,
'smooth': None})
@if_statsmodels
def test_linear_fit(self):
from statsmodels.regression.linear_model import GLS, OLS
self.earth.fit(self.X, self.y)
self.earth._Earth__linear_fit(self.X, self.y)
soln = OLS(self.y, self.earth.transform(self.X)).fit().params
assert_almost_equal(numpy.mean((self.earth.coef_ - soln) ** 2), 0.0)
sample_weight = 1.0 / (numpy.random.normal(size=self.y.shape) ** 2)
self.earth.fit(self.X, self.y)
self.earth._Earth__linear_fit(self.X, self.y, sample_weight)
soln = GLS(self.y, self.earth.transform(
self.X), 1.0 / sample_weight).fit().params
assert_almost_equal(numpy.mean((self.earth.coef_ - soln) ** 2), 0.0)
def test_sample_weight(self):
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, 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)
# Uncomment below to see what this test situation looks like
# from matplotlib import pyplot
# print model.summary()
# print model.score(x,y,sample_weight = sample_weight)
# pyplot.figure()
# pyplot.plot(x,y,'b.')
# pyplot.plot(x,model.predict(x),'r.')
# pyplot.show()
def test_fit(self):
self.earth.fit(self.X, self.y)
res = str(self.earth.trace()) + '\n' + self.earth.summary()
# fl.write(res)
filename = os.path.join(os.path.dirname(__file__),
'earth_regress.txt')
with open(filename, 'r') as fl:
prev = fl.read()
assert_equal(res, prev)
def test_smooth(self):
model = Earth(penalty=1, smooth=True)
model.fit(self.X, self.y)
res = str(model.trace()) + '\n' + model.summary()
#.........这里部分代码省略.........