Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit da856e1

Browse files
authored
Merge pull request #160 from scikit-learn-contrib/release_prep
Release prep
2 parents f32e542 + 41b9c7a commit da856e1

File tree

11 files changed

+86
-92
lines changed

11 files changed

+86
-92
lines changed

appveyor.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,10 @@ install:
4646
# Install the build and runtime dependencies of the project.
4747
- "conda install --quiet --yes six numpy pandas sympy scipy cython nose scikit-learn wheel conda-build"
4848
- "pip install sphinx-gallery"
49-
- "python setup.py build_ext --inplace --cythonize"
5049
- "python setup.py bdist_wheel bdist_wininst"
50+
- "python setup.py build_ext --inplace --cythonize"
51+
5152
- ps: "ls"
52-
# build the conda package
53-
- "conda build conda-recipe"
54-
# Move the conda package into the dist directory, to register it
55-
# as an "artifact" for Appveyor. cmd.exe does't have good globbing, so
56-
# we'll use a simple python script.
57-
- "python conda-recipe/move-conda-package.py conda-recipe"
5853

5954
# Install the generated wheel package to test it
6055
- "pip install --pre --no-index --find-links dist/ py-earth"

description.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The py-earth package implements Multivariate Adaptive Regression Splines and provides an interface that is compatible with scikit-learn's Estimator, Predictor, Transformer, and Model interfaces.

pyearth/earth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,13 @@ def _scrub(self, X, y, sample_weight, output_weight, missing, **kwargs):
463463
if sample_weight is None:
464464
sample_weight = np.ones((y.shape[0], 1), dtype=y.dtype)
465465
else:
466-
sample_weight = np.asarray(sample_weight)
466+
sample_weight = np.asarray(sample_weight, dtype=np.float64)
467467
assert_all_finite(sample_weight)
468468
if len(sample_weight.shape) == 1:
469469
sample_weight = sample_weight[:, np.newaxis]
470470
# Deal with output_weight
471471
if output_weight is not None:
472-
output_weight = np.asarray(output_weight)
472+
output_weight = np.asarray(output_weight, dtype=np.float64)
473473
assert_all_finite(output_weight)
474474

475475
# Make sure dimensions match
Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1 @@
1-
Forward Pass
2-
---------------------------------------------------------------
3-
iter parent var knot mse terms gcv rsq grsq
4-
---------------------------------------------------------------
5-
0 - - - 1.373069 1 1.401 0.000 0.000
6-
1 0 1 -1 0.861043 2 0.906 0.373 0.353
7-
2 0 2 -1 0.774582 3 0.840 0.436 0.400
8-
3 0 3 -1 0.764313 4 0.856 0.443 0.389
9-
4 0 6 -1 0.753043 5 0.871 0.452 0.379
10-
5 0 5 -1 0.740056 6 0.884 0.461 0.369
11-
6 0 7 -1 0.734362 7 0.907 0.465 0.353
12-
7 0 8 -1 0.732358 8 0.935 0.467 0.333
13-
8 0 4 -1 0.731261 9 0.966 0.467 0.310
14-
---------------------------------------------------------------
15-
Stopping Condition 2: Improvement below threshold
16-
17-
Pruning Pass
18-
--------------------------------------------
19-
iter bf terms mse gcv rsq grsq
20-
--------------------------------------------
21-
0 - 9 0.73 0.966 0.467 0.310
22-
1 8 8 0.73 0.935 0.467 0.333
23-
2 7 7 0.73 0.907 0.465 0.353
24-
3 6 6 0.74 0.884 0.461 0.369
25-
4 5 5 0.75 0.871 0.452 0.379
26-
5 4 4 0.76 0.856 0.443 0.389
27-
6 3 3 0.77 0.840 0.436 0.400
28-
7 2 2 0.86 0.906 0.373 0.353
29-
8 1 1 1.37 1.401 0.000 0.000
30-
--------------------------------------------
31-
Selected iteration: 6
32-
33-
Earth Model
34-
-------------------------------------
35-
Basis Function Pruned Coefficient
36-
-------------------------------------
37-
(Intercept) No 0.657403
38-
x1 No 0.757872
39-
x2 No 0.325515
40-
x3 Yes None
41-
x6 Yes None
42-
x5 Yes None
43-
x7 Yes None
44-
x8 Yes None
45-
x4 Yes None
46-
-------------------------------------
47-
MSE: 0.7746, GCV: 0.8405, RSQ: 0.4359, GRSQ: 0.4001
1+
0.151785846961

pyearth/test/earth_regress.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.513434373667
1+
0.219175992389
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.471040262964
1+
0.178314473548
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.493873566832
1+
0.209074299412

pyearth/test/test_earth.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from .testing_utils import (if_statsmodels, if_pandas, if_patsy,
1010
if_environ_has, assert_list_almost_equal_value,
1111
assert_list_almost_equal,
12-
if_sklearn_version_greater_than_or_equal_to)
12+
if_sklearn_version_greater_than_or_equal_to,
13+
if_platform_not_win_32)
1314
from nose.tools import (assert_equal, assert_true, assert_almost_equal,
1415
assert_list_equal, assert_raises, assert_not_equal)
1516
import numpy
@@ -19,9 +20,11 @@
1920
HingeBasisFunction, LinearBasisFunction)
2021
from pyearth import Earth
2122
import pyearth
23+
from numpy.testing.utils import assert_array_almost_equal
2224

23-
numpy.random.seed(0)
25+
regenerate_target_files = False
2426

27+
numpy.random.seed(1)
2528
basis = Basis(10)
2629
constant = ConstantBasisFunction()
2730
basis.append(constant)
@@ -31,18 +34,19 @@
3134
basis.append(bf1)
3235
basis.append(bf2)
3336
basis.append(bf3)
34-
X = numpy.random.normal(size=(100, 10))
37+
X = numpy.random.normal(size=(1000, 10))
3538
missing = numpy.zeros_like(X, dtype=BOOL)
36-
B = numpy.empty(shape=(100, 4), dtype=numpy.float64)
39+
B = numpy.empty(shape=(1000, 4), dtype=numpy.float64)
3740
basis.transform(X, missing, B)
3841
beta = numpy.random.normal(size=4)
39-
y = numpy.empty(shape=100, dtype=numpy.float64)
40-
y[:] = numpy.dot(B, beta) + numpy.random.normal(size=100)
42+
y = numpy.empty(shape=1000, dtype=numpy.float64)
43+
y[:] = numpy.dot(B, beta) + numpy.random.normal(size=1000)
4144
default_params = {"penalty": 1}
4245

43-
46+
@if_platform_not_win_32
4447
@if_sklearn_version_greater_than_or_equal_to('0.17.2')
4548
def test_check_estimator():
49+
numpy.random.seed(0)
4650
import sklearn.utils.estimator_checks
4751
sklearn.utils.estimator_checks.MULTI_OUTPUT.append('Earth')
4852
sklearn.utils.estimator_checks.check_estimator(Earth)
@@ -149,6 +153,7 @@ def test_output_weight():
149153

150154

151155
def test_missing_data():
156+
numpy.random.seed(0)
152157
earth = Earth(allow_missing=True, **default_params)
153158
missing_ = numpy.random.binomial(1, .05, X.shape).astype(bool)
154159
X_ = X.copy()
@@ -157,34 +162,42 @@ def test_missing_data():
157162
res = str(earth.score(X_, y))
158163
filename = os.path.join(os.path.dirname(__file__),
159164
'earth_regress_missing_data.txt')
160-
# with open(filename, 'w') as fl:
161-
# fl.write(res)
165+
if regenerate_target_files:
166+
with open(filename, 'w') as fl:
167+
fl.write(res)
162168
with open(filename, 'r') as fl:
163169
prev = fl.read()
164-
assert_true(abs(float(res) - float(prev)) < .03)
165-
170+
try:
171+
assert_true(abs(float(res) - float(prev)) < .03)
172+
except AssertionError:
173+
print('Got %f, %f' % (float(res), float(prev)))
174+
raise
166175

167176
def test_fit():
177+
numpy.random.seed(0)
168178
earth = Earth(**default_params)
169179
earth.fit(X, y)
170180
res = str(earth.rsq_)
171181
filename = os.path.join(os.path.dirname(__file__),
172182
'earth_regress.txt')
173-
# with open(filename, 'w') as fl:
174-
# fl.write(res)
183+
if regenerate_target_files:
184+
with open(filename, 'w') as fl:
185+
fl.write(res)
175186
with open(filename, 'r') as fl:
176187
prev = fl.read()
177188
assert_true(abs(float(res) - float(prev)) < .05)
178189

179190

180191
def test_smooth():
192+
numpy.random.seed(0)
181193
model = Earth(penalty=1, smooth=True)
182194
model.fit(X, y)
183195
res = str(model.rsq_)
184196
filename = os.path.join(os.path.dirname(__file__),
185197
'earth_regress_smooth.txt')
186-
# with open(filename, 'w') as fl:
187-
# fl.write(res)
198+
if regenerate_target_files:
199+
with open(filename, 'w') as fl:
200+
fl.write(res)
188201
with open(filename, 'r') as fl:
189202
prev = fl.read()
190203
assert_true(abs(float(res) - float(prev)) < .05)
@@ -193,11 +206,12 @@ def test_smooth():
193206
def test_linvars():
194207
earth = Earth(**default_params)
195208
earth.fit(X, y, linvars=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
196-
res = str(earth.trace()) + '\n' + earth.summary()
209+
res = str(earth.rsq_)
197210
filename = os.path.join(os.path.dirname(__file__),
198211
'earth_linvars_regress.txt')
199-
# with open(filename, 'w') as fl:
200-
# fl.write(res)
212+
if regenerate_target_files:
213+
with open(filename, 'w') as fl:
214+
fl.write(res)
201215
with open(filename, 'r') as fl:
202216
prev = fl.read()
203217

@@ -301,8 +315,7 @@ def test_pickle_compatibility():
301315
model = earth.fit(X, y)
302316
model_copy = pickle.loads(pickle.dumps(model))
303317
assert_true(model_copy == model)
304-
assert_true(
305-
numpy.all(model.predict(X) == model_copy.predict(X)))
318+
assert_array_almost_equal(model.predict(X), model_copy.predict(X))
306319
assert_true(model.basis_[0] is model.basis_[1]._get_root())
307320
assert_true(model_copy.basis_[0] is model_copy.basis_[1]._get_root())
308321

@@ -318,11 +331,11 @@ def test_pickle_version_storage():
318331

319332

320333
def test_copy_compatibility():
334+
numpy.random.seed(0)
321335
model = Earth(**default_params).fit(X, y)
322336
model_copy = copy.copy(model)
323337
assert_true(model_copy == model)
324-
assert_true(
325-
numpy.all(model.predict(X) == model_copy.predict(X)))
338+
assert_array_almost_equal(model.predict(X), model_copy.predict(X))
326339
assert_true(model.basis_[0] is model.basis_[1]._get_root())
327340
assert_true(model_copy.basis_[0] is model_copy.basis_[1]._get_root())
328341

pyearth/test/testing_utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from nose import SkipTest
44
from nose.tools import assert_almost_equal
55
from distutils.version import LooseVersion
6-
6+
import sys
77

88
def if_environ_has(var_name):
99
# Test decorator that skips test if environment variable is not defined
@@ -18,7 +18,15 @@ def run_test(*args, **kwargs):
1818
return run_test
1919
return if_environ
2020

21-
21+
def if_platform_not_win_32(func):
22+
@wraps(func)
23+
def run_test(*args, **kwargs):
24+
if sys.platform == 'win32':
25+
raise SkipTest('Skip for 32 bit Windows platforms.')
26+
else:
27+
return func(*args, **kwargs)
28+
return run_test
29+
2230
def if_sklearn_version_greater_than_or_equal_to(min_version):
2331
'''
2432
Test decorator that skips test unless sklearn version is greater than or

setup.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ style = pep440
44
versionfile_source = pyearth/_version.py
55
versionfile_build = pyearth/_version.py
66
tag_prefix=
7-
parentdir_prefix = py-earth
7+
parentdir_prefix = py-earth
8+
9+
[metadata]
10+
description-file = description.md
11+
license_file = LICENSE.txt

0 commit comments

Comments
 (0)