Skip to content

Commit

Permalink
add type_ci to summary -> v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Aug 27, 2024
1 parent 3ec7ca9 commit f51138e
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 215 deletions.
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ coverage: ## check code coverage quickly with the default Python
coverage html
$(BROWSER) htmlcov/index.html

docs: ## generate docs
pip install pdoc --ignore-installed
pdoc learningmachine/* --output-dir learningmachine-docs
docs: install ## generate docs
pip install black pdoc
black learningmachine/* --line-length=80
find learningmachine/ -name "*.py" -exec autopep8 --max-line-length=80 --in-place {} +
pdoc -t docs learningmachine/* --output-dir learningmachine-docs
find . -name '__pycache__' -exec rm -fr {} +

servedocs: ## compile the docs watching for change
pip install pdoc --ignore-installed
pdoc learningmachine/*
servedocs: install ## compile the docs watching for change
pip install black pdoc
black learningmachine/* --line-length=80
find learningmachine/ -name "*.py" -exec autopep8 --max-line-length=80 --in-place {} +
pdoc -t docs learningmachine/*
find . -name '__pycache__' -exec rm -fr {} +

release: dist ## package and upload a release
pip install twine
Expand All @@ -76,10 +82,9 @@ install: clean ## install the package to the active Python's site-packages
##python3 -m black learningmachine --line-length 80
python3 -m pip install .

build-site: docs ## export mkdocs website to a folder
cd docs&&mkdocs build
cp -rf docs/site/* ../../Pro_Website/Techtonique.github.io/learningmachine
cd ..
build-site: docs ## export mkdocs website to a folder
cp -rf learningmachine-docs/* ../../Pro_Website/Techtonique.github.io/learningmachine
find . -name '__pycache__' -exec rm -fr {} +

run-examples: ## run all examples with one command
find examples -maxdepth 2 -name "*.py" -exec python3 {} \;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# learningmachine

![PyPI](https://img.shields.io/pypi/v/learningmachine) [![PyPI - License](https://img.shields.io/pypi/l/learningmachine)](https://github.com/thierrymoudiki/learningmachine/blob/master/LICENSE) [![Downloads](https://pepy.tech/badge/learningmachine)](https://pepy.tech/project/learningmachine)
![PyPI](https://img.shields.io/pypi/v/learningmachine) [![PyPI - License](https://img.shields.io/pypi/l/learningmachine)](https://github.com/thierrymoudiki/learningmachine/blob/master/LICENSE) [![Downloads](https://pepy.tech/badge/learningmachine)](https://pepy.tech/project/learningmachine) [![Documentation](https://img.shields.io/badge/documentation-is_here-green)](https://techtonique.github.io/learningmachine/)


Machine Learning with uncertainty quantification and interpretability.
Expand Down
110 changes: 68 additions & 42 deletions learningmachine/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pandas as pd
import pandas as pd
import sklearn.metrics as skm
import subprocess
from functools import lru_cache
Expand Down Expand Up @@ -32,9 +32,9 @@ def __init__(
pi_method="kdesplitconformal",
level=95,
B=100,
nb_hidden = 0,
nodes_sim = "sobol",
activ = "relu",
nb_hidden=0,
nodes_sim="sobol",
activ="relu",
params=None,
seed=123,
):
Expand All @@ -47,24 +47,34 @@ def __init__(
self.method = method
self.pi_method = pi_method
self.level = level
self.B = B
self.B = B
self.nb_hidden = nb_hidden
assert nodes_sim in ("sobol", "halton", "unif"), \
"must have nodes_sim in ('sobol', 'halton', 'unif')"
assert nodes_sim in (
"sobol",
"halton",
"unif",
), "must have nodes_sim in ('sobol', 'halton', 'unif')"
self.nodes_sim = "sobol"
assert activ in ("relu", "sigmoid", "tanh",
"leakyrelu", "elu", "linear"), \
"must have activ in ('relu', 'sigmoid', 'tanh', 'leakyrelu', 'elu', 'linear')"
self.activ = activ
assert activ in (
"relu",
"sigmoid",
"tanh",
"leakyrelu",
"elu",
"linear",
), "must have activ in ('relu', 'sigmoid', 'tanh', 'leakyrelu', 'elu', 'linear')"
self.activ = activ
self.params = params
self.seed = seed
self.obj = None
self.column_names = None

def load_learningmachine(self):
# Install R packages
commands1_lm = 'base::system.file(package = "learningmachine")' # check "learningmachine" is installed
commands2_lm = 'base::system.file("learningmachine_r", package = "learningmachine")' # check "learningmachine" is installed locally
# check "learningmachine" is installed
commands1_lm = 'base::system.file(package = "learningmachine")'
# check "learningmachine" is installed locally
commands2_lm = 'base::system.file("learningmachine_r", package = "learningmachine")'
exec_commands1_lm = subprocess.run(
["Rscript", "-e", commands1_lm], capture_output=True, text=True
)
Expand Down Expand Up @@ -102,7 +112,9 @@ def load_learningmachine(self):
)
except: # well, we tried
try:
r("try(suppressWarnings(suppressMessages(library('learningmachine'))), silence=TRUE)")
r(
"try(suppressWarnings(suppressMessages(library('learningmachine'))), silence=TRUE)"
)
except: # well, we tried everything at this point
r(
"try(suppressWarnings(suppressMessages(library('learningmachine', lib.loc='learningmachine_r'))), silence=TRUE)"
Expand Down Expand Up @@ -214,43 +226,57 @@ def score(self, X, y, scoring=None, **kwargs):

return scoring_options[scoring](y, preds, **kwargs)

def summary(self, X, y,
class_index = None,
cl = None,
show_progress = True):

if isinstance(X, pd.DataFrame):
X_r = r.matrix(FloatVector(X.values.ravel()),
byrow=True,
ncol=X.shape[1],
nrow=X.shape[0])
def summary(
self,
X,
y,
class_index=None,
cl=None,
type_ci="student",
show_progress=True,
):

if isinstance(X, pd.DataFrame):
X_r = r.matrix(
FloatVector(X.values.ravel()),
byrow=True,
ncol=X.shape[1],
nrow=X.shape[0],
)
X_r.colnames = StrVector(self.column_names)
else:
X_r = r.matrix(FloatVector(X.ravel()),
byrow=True,
ncol=X.shape[1],
nrow=X.shape[0])

X_r = r.matrix(
FloatVector(X.ravel()),
byrow=True,
ncol=X.shape[1],
nrow=X.shape[0],
)

if cl is None:

if self.type == "classification":

assert class_index is not None, "For classifiers, 'class_index' must be provided"
assert (
class_index is not None
), "For classifiers, 'class_index' must be provided"

return self.obj["summary"](X = X_r,
y = FactorVector(IntVector(y)),
class_index = int(class_index) + 1,
show_progress = show_progress
return self.obj["summary"](
X=X_r,
y=FactorVector(IntVector(y)),
class_index=int(class_index) + 1,
type_ci=StrVector([type_ci]),
show_progress=show_progress,
)

elif self.type == "regression":

return self.obj["summary"](X = X_r,
y = FloatVector(y),
show_progress = show_progress

return self.obj["summary"](
X=X_r,
y=FloatVector(y),
type_ci=StrVector([type_ci]),
show_progress=show_progress,
)

else: # cl is not None, parallel computing

pass
else: # cl is not None, parallel computing

pass
Loading

0 comments on commit f51138e

Please sign in to comment.