Skip to content

Commit 2ece40c

Browse files
committed
make viz.fit_line a public function
1 parent b5433aa commit 2ece40c

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

probscale/tests/test_viz.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
BASELINE_DIR = 'baseline_images/test_viz'
2323

2424

25-
class Test__fit_line(object):
25+
class Test_fit_line(object):
2626
def setup(self):
2727
self.data = numpy.array([
2828
2.00, 4.0 , 4.62, 5.00, 5.00, 5.50, 5.57, 5.66,
@@ -71,56 +71,56 @@ def setup(self):
7171
def test_xlinear_ylinear(self):
7272
scales = {'fitlogs': None, 'fitprobs': None}
7373
x, y = self.zscores, self.data
74-
x_, y_, res = viz._fit_line(x, y, **scales)
74+
x_, y_, res = viz.fit_line(x, y, **scales)
7575
nptest.assert_array_almost_equal(y_, self.known_y_linlin)
7676
assert isinstance(res, numpy.ndarray)
7777

7878
def test_xlinear_ylog(self):
7979
scales = {'fitlogs': 'y', 'fitprobs': None}
8080
x, y = self.zscores, self.data
81-
x_, y_, res = viz._fit_line(x, y, **scales)
81+
x_, y_, res = viz.fit_line(x, y, **scales)
8282
nptest.assert_array_almost_equal(y_, self.known_y_linlog)
8383
assert isinstance(res, numpy.ndarray)
8484

8585
def test_xlinear_yprob(self):
8686
scales = {'fitlogs': None, 'fitprobs': 'y'}
8787
x, y = self.data, self.probs
88-
x_, y_, res = viz._fit_line(x, y, **scales)
88+
x_, y_, res = viz.fit_line(x, y, **scales)
8989
nptest.assert_array_almost_equal(y_, self.known_y_linprob)
9090
assert isinstance(res, numpy.ndarray)
9191

9292
def test_xlog_ylinear(self):
9393
scales = {'fitlogs': 'x', 'fitprobs': None}
9494
x, y = self.data, self.zscores
95-
x_, y_, res = viz._fit_line(x, y, **scales)
95+
x_, y_, res = viz.fit_line(x, y, **scales)
9696
nptest.assert_array_almost_equal(y_, self.known_y_loglin)
9797
assert isinstance(res, numpy.ndarray)
9898

9999
def test_xlog_ylog(self):
100100
scales = {'fitlogs': 'both', 'fitprobs': None}
101101
x, y = self.data, self.y
102-
x_, y_, res = viz._fit_line(x, y, **scales)
102+
x_, y_, res = viz.fit_line(x, y, **scales)
103103
nptest.assert_array_almost_equal(y_, self.known_y_loglog)
104104
assert isinstance(res, numpy.ndarray)
105105

106106
def test_xlog_yprob(self):
107107
scales = {'fitlogs': 'x', 'fitprobs': 'y'}
108108
x, y = self.data, self.probs
109-
x_, y_, res = viz._fit_line(x, y, **scales)
109+
x_, y_, res = viz.fit_line(x, y, **scales)
110110
nptest.assert_array_almost_equal(y_, self.known_y_logprob)
111111
assert isinstance(res, numpy.ndarray)
112112

113113
def test_xprob_ylinear(self):
114114
scales = {'fitlogs': None, 'fitprobs': 'x'}
115115
x, y = self.probs, self.data
116-
x_, y_, res = viz._fit_line(x, y, **scales)
116+
x_, y_, res = viz.fit_line(x, y, **scales)
117117
nptest.assert_array_almost_equal(y_, self.known_y_problin)
118118
assert isinstance(res, numpy.ndarray)
119119

120120
def test_xprob_ylog(self):
121121
scales = {'fitlogs': 'y', 'fitprobs': 'x'}
122122
x, y = self.probs, self.data
123-
x_, y_, res = viz._fit_line(x, y, **scales)
123+
x_, y_, res = viz.fit_line(x, y, **scales)
124124
nptest.assert_array_almost_equal(y_, self.known_y_problog)
125125
assert isinstance(res, numpy.ndarray)
126126

@@ -139,23 +139,23 @@ def test_xprob_yprob(self):
139139

140140
scales = {'fitlogs': None, 'fitprobs': 'both'}
141141
x, y = self.probs, p2,
142-
x_, y_, res = viz._fit_line(x, y, **scales)
142+
x_, y_, res = viz.fit_line(x, y, **scales)
143143
nptest.assert_array_almost_equal(y_, self.known_y_probprob)
144144
assert isinstance(res, numpy.ndarray)
145145

146146
def test_bad_fitlogs(self):
147147
with pytest.raises(ValueError):
148148
x, y = self.zscores, self.data
149-
x_, y_, res = viz._fit_line(x, y, fitlogs='junk')
149+
x_, y_, res = viz.fit_line(x, y, fitlogs='junk')
150150

151151
def test_bad_fitprobs(self):
152152
with pytest.raises(ValueError):
153153
x, y = self.zscores, self.data
154-
x_, y_, res = viz._fit_line(x, y, fitprobs='junk')
154+
x_, y_, res = viz.fit_line(x, y, fitprobs='junk')
155155

156156
def test_custom_xhat(self):
157157
x, y = self.zscores, self.data
158-
x_, y_, res = viz._fit_line(x, y, xhat=self.custom_xhat)
158+
x_, y_, res = viz.fit_line(x, y, xhat=self.custom_xhat)
159159
nptest.assert_array_almost_equal(y_, self.known_custom_yhat)
160160

161161

probscale/viz.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def probplot(data, ax=None, plottype='prob', dist=None, probax='x',
189189

190190
# maybe do a best-fit and plot
191191
if bestfit:
192-
xhat, yhat, modelres = _fit_line(x, y, fitprobs=fitprobs, fitlogs=fitlogs, dist=dist)
192+
xhat, yhat, modelres = fit_line(x, y, fitprobs=fitprobs, fitlogs=fitlogs, dist=dist)
193193
ax.plot(xhat, yhat, **line_kws)
194194
else:
195195
xhat, yhat, modelres = (None, None, None)
@@ -337,7 +337,8 @@ def _set_prob_limits(ax, probax, N):
337337
ax.set_ylim(bottom=minval, top=100-minval)
338338

339339

340-
def _fit_line(x, y, xhat=None, fitprobs=None, fitlogs=None, dist=None):
340+
def fit_line(x, y, xhat=None, fitprobs=None, fitlogs=None, dist=None,
341+
estimate_ci=False, niter=10000, alpha=0.05):
341342
"""
342343
Fits a line to x-y data in various forms (linear, log, prob scales).
343344

0 commit comments

Comments
 (0)