Skip to content

Commit

Permalink
We can now explicitely give the breakpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezibenroc committed Jun 12, 2018
1 parent 971cbe5 commit 1d3b42d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pytree/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def merge(self):
return leaf


def compute_regression(x, y=None, *, simplify=False, mode='BIC', epsilon=None):
def compute_regression(x, y=None, *, breakpoints=None, simplify=False, mode='BIC', epsilon=None):
'''Compute a segmented linear regression.
The data can be given either as a tuple of two lists, or a list of tuples (each one of size 2).
The first values represent the x, the second values represent the y.
Expand All @@ -853,6 +853,8 @@ def compute_regression(x, y=None, *, simplify=False, mode='BIC', epsilon=None):
else:
epsilon = min([abs(yy) for yy in y])
config = Config(mode, epsilon)
if breakpoints:
return FlatRegression(x, y, config=config, breakpoints=breakpoints)
reg = Node(Leaf(x, y, config=config), Leaf(
[], [], config=config)).compute_best_fit()
if statsmodels and simplify:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup
import subprocess

VERSION = '0.0.1'
VERSION = '0.0.2'


class CommandError(Exception):
Expand Down
2 changes: 2 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ def generic_multiplesplits(self, cls, repeat):
for x, y in dataset:
prediction = flat_reg.predict(x)
self.assertAlmostEqual(y, prediction)
other_flat = compute_regression(dataset, breakpoints=flat_reg.breakpoints)
self.assertEqual(str(other_flat), str(flat_reg))

def test_multiple_splits(self):
self.generic_multiplesplits(float, 1)
Expand Down

0 comments on commit 1d3b42d

Please sign in to comment.