Skip to content

Commit

Permalink
Missing metadata (#170)
Browse files Browse the repository at this point in the history
* TST: Fixing metadata

* STY: removing references to bokeh charts

* STY: fixing spacing

* Removing red ray, because bokeh has super weird scaling going on
  • Loading branch information
mortonjt authored Apr 26, 2017
1 parent 13ce936 commit 510cb96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 0 additions & 6 deletions gneiss/plot/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ def ols_summary(output_dir: str, model: OLSModel, ndim=10) -> None:
mse_p.quad(top=mse_hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#FFFF00", line_color="#033649", fill_alpha=0.5,
legend='CV Mean Squared Error')
mse_p.ray(x=model.mse, y=0, length=h*max(mse_hist),
angle=1.57079633, color='red',
legend='Model Error', line_width=0.5)

# Histogram of prediction error from cross validation
pred_p = figure(title="Prediction Error",
Expand All @@ -300,9 +297,6 @@ def ols_summary(output_dir: str, model: OLSModel, ndim=10) -> None:
pred_p.quad(top=pred_hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#00FFFF", line_color="#033649", fill_alpha=0.5,
legend='Prediction Error')
pred_p.ray(x=model.mse, y=0, length=h,
angle=1.57079633, color='red',
legend='Model Error', line_width=0.5)

# Explained sum of squares
ess = pd.Series({r.model.endog_names: r.ess for r in model.results})
Expand Down
2 changes: 1 addition & 1 deletion gneiss/regression/_ols.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ def ols(formula, table, metadata, tree, **kwargs):
tree)
ilr_table, basis = _to_balances(table, tree)

ilr_table, metadata = ilr_table.align(metadata, join='inner', axis=0)
# one-time creation of exogenous data matrix allows for faster run-time
metadata = _type_cast_to_float(metadata)
x = dmatrix(formula, metadata, return_type='dataframe')

ilr_table, x = ilr_table.align(x, join='inner', axis=0)
submodels = _fit_ols(ilr_table, x)

basis = pd.DataFrame(basis, index=ilr_table.columns,
Expand Down
31 changes: 31 additions & 0 deletions gneiss/regression/tests/test_ols.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,37 @@ def test_ols_immutable(self):
self.assertEqual(str(table), str(exp_table))
self.assertEqual(str(exp_tree), str(res.tree))

def test_ols_missing_metadata(self):
np.random.seed(0)
A = np.array # aliasing for the sake of pep8
table = pd.DataFrame({
's1': ilr_inv(A([1., 1.])),
's2': ilr_inv(A([1., 2.])),
's3': ilr_inv(A([1., 3.])),
's4': ilr_inv(A([1., 4.])),
's5': ilr_inv(A([1., 5.])),
's6': ilr_inv(A([1., 5.])),
's7': ilr_inv(A([1., 5.]))},
index=['a', 'b', 'c']).T

tree = TreeNode.read(['((c,d),(b,a));'])
exp_tree = TreeNode.read(['((b,a)y1,c)y0;\n'])
metadata = pd.DataFrame({
'lame': [1, 1, 1, 1, 1, 0],
'real': [1, 2, 3, 4, 5, np.nan]
}, index=['s1', 's2', 's3', 's4', 's5', 's7'])

res = ols('real + lame', table, metadata, tree)
res.fit()
self.assertEqual(str(exp_tree), str(res.tree))

exp_coefs = pd.DataFrame(
[[-7.494005e-16, -7.494005e-16, -1.000000e+00],
[5.000000e-01, 5.000000e-01, -1.294503e-16]],
columns=['Intercept', 'lame', 'real'], index=['y0', 'y1'])
pdt.assert_frame_equal(exp_coefs, res.coefficients(),
check_less_precise=True)

def test_ols_empty_table_error(self):
A = np.array # aliasing for the sake of pep8
table = pd.DataFrame({
Expand Down

0 comments on commit 510cb96

Please sign in to comment.