Skip to content

Commit

Permalink
add _sigfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jkitchin committed Jul 8, 2024
1 parent 301b04f commit 09cb6fa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pycse/sklearn/surface_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def parity(self):

return plt.gcf()

def _sigfig(self, x, n=3):
"""Round X to N significant figures."""
# Adapted from https://gist.github.com/ttamg/3f65227fd580b3d8dc8ba91e01507280
return np.round(x, -int(np.floor(np.log10(np.abs(x)))) + (n - 1))

def summary(self):
X, y = self.input, self.output

Expand All @@ -126,11 +131,14 @@ def summary(self):

nrows, ncols = pars.shape

mae = [self._sigfig(x) for x in (np.abs(errs).mean())]
rmse = [self._sigfig(x) for x in (errs**2).mean()]

s += [f" score: {self.score(X, y)}"]
s += [
f" mae = {(np.abs(errs).mean().tolist())}",
f" mae = {(mae)}",
"",
f" rmse = {(errs**2).mean().tolist()}",
f" rmse = {rmse}",
"",
]

Expand All @@ -141,6 +149,7 @@ def summary(self):
data += [
[
f"{name}_{i}",
pars[j][i],
pars_cint[0][j][i],
pars_cint[1][j][i],
pars_se[j][i],
Expand All @@ -150,7 +159,7 @@ def summary(self):
s += [
tabulate.tabulate(
data,
headers=["var", "ci_lower", "ci_upper", "se", "significant"],
headers=["var", "value", "ci_lower", "ci_upper", "se", "significant"],
tablefmt="orgtbl",
)
]
Expand Down

0 comments on commit 09cb6fa

Please sign in to comment.