Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dda8fbe
Update link to make git clone
alvespatrick May 16, 2023
019f3f0
Fix documetation
alvespatrick May 16, 2023
72b342b
Add xai tools
alvespatrick Oct 5, 2023
94a50ba
Add balanced accuracy
alvespatrick Oct 26, 2023
d18d675
Fix conflits
alvespatrick Oct 26, 2023
3fdb195
Update xai file
alvespatrick Nov 8, 2023
0fa6367
Fix xay documentation and functions to calculate global feature impor…
alvespatrick Nov 10, 2023
f59a57b
Update path to load data
alvespatrick Nov 11, 2023
a411efd
Update data_path
alvespatrick Nov 11, 2023
62ac18e
Update
alvespatrick Nov 11, 2023
3d7145e
Fix Lime
alvespatrick Nov 11, 2023
24fdd25
Fix dataframe concatenate
alvespatrick Nov 11, 2023
9bcc43b
Fix dataframe concatenate
alvespatrick Nov 11, 2023
2b1d483
Fix functions to calculate feature importance with lime
alvespatrick Nov 11, 2023
d838797
Fix bug
alvespatrick Nov 15, 2023
6ca943b
Add condition to take only real part if we don't want to calculate th…
alvespatrick Dec 20, 2023
5208153
Merge branch 'master' into organize_documentation
alvespatrick Apr 13, 2024
1f4a26a
Add geometric mean in report
alvespatrick Apr 15, 2024
17f9df4
Update load data function
alvespatrick Apr 18, 2024
ef3893e
Add more estimators
alvespatrick Apr 23, 2024
a30cc16
Fix geometric mean
alvespatrick Apr 23, 2024
5d93257
Add more transforms
alvespatrick Apr 23, 2024
a20f660
Import numpy
alvespatrick Apr 23, 2024
25b4e3f
Remove print path
alvespatrick Apr 23, 2024
62284b0
Modify the shap values computation and generalize the dimensions
alvespatrick Apr 24, 2024
6cf3086
Update function
alvespatrick Apr 25, 2024
fce27e0
Rename feature name
alvespatrick Apr 25, 2024
bca324c
Fix file
alvespatrick Jun 12, 2024
6c78a31
Remove unusen variabel
alvespatrick Jun 27, 2024
dcd8bd6
Update xai file
alvespatrick Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
To install `librep`, you may use:

```
pip install git+https://github.com/otavioon/hiaac-librep.git
pip install git+https://github.com/discovery-unicamp/hiaac-librep.git
```

### Pip optional dependencies
Expand All @@ -22,7 +22,7 @@ In order to contribute with `librep` you may want to:
1. Clone librep's repository:

```
git clone https://github.com/otavioon/hiaac-librep.git
git clone https://github.com/discovery-unicamp/hiaac-librep.git
```

2. Create a python virtual environment and activate it (requires Python >= 3.8):
Expand All @@ -36,7 +36,7 @@ source .librep-venv/bin/activate
3. Install librep development packages, in editable mode

```
pip install -e .[dev]
pip install -e .[dev] (we need to fix the flag [dev])
```

4. Run tests
Expand Down
1 change: 1 addition & 0 deletions src/librep/config/type_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

# PathLike: The PathLike type is used for defining a file path.
PathLike = Union[str, os.PathLike]
# ArrayLike = Union[numpy.ndarray, list]
ArrayLike = Union[numpy.ndarray, pd.DataFrame, Iterable]
KeyType = Hashable
4 changes: 3 additions & 1 deletion src/librep/estimators/sklearn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from sklearn.neighbors import *
from sklearn.ensemble import *
from sklearn.svm import *
from sklearn.svm import *
from sklearn.tree import *
from sklearn.linear_model import *
38 changes: 38 additions & 0 deletions src/librep/metrics/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
classification_report,
accuracy_score,
f1_score,
balanced_accuracy_score,
recall_score,
precision_score,
confusion_matrix,
ConfusionMatrixDisplay
)
import matplotlib.pyplot as plt
import numpy as np

from librep.base.evaluators import SupervisedEvaluator
from librep.config.type_definitions import ArrayLike, PathLike
Expand All @@ -18,6 +22,10 @@ def __init__(
self,
use_accuracy: bool = True,
use_f1_score: bool = True,
use_balanced_accuracy: bool = False,
use_precision: bool = True,
use_recall: bool = True,
use_geometric_mean: bool = True,
use_confusion_matrix: bool = True,
use_classification_report: bool = False,
plot_confusion_matrix: bool = True,
Expand All @@ -29,6 +37,10 @@ def __init__(
):
self.use_accuracy = use_accuracy
self.use_f1_score = use_f1_score
self.use_balanced_accuracy = use_balanced_accuracy
self.use_precision = use_precision
self.use_recall = use_recall
self.use_geometric_mean = use_geometric_mean
self.use_confusion_matrix = use_confusion_matrix
self.use_classification_report = use_classification_report
self.plot_confusion_matrix = plot_confusion_matrix
Expand Down Expand Up @@ -59,6 +71,32 @@ def evaluate(

res = f1_score(y_true, y_pred, average="macro")
result["f1 score (macro)"] = float(res)

if self.use_balanced_accuracy:
res = balanced_accuracy_score(y_true, y_pred)
result["balanced accuracy"] = float(res)
if self.use_precision:
res = precision_score(y_true, y_pred, average="weighted")
result["precision (weighted)"] = float(res)

res = precision_score(y_true, y_pred, average="micro")
result["precision (micro)"] = float(res)

res = precision_score(y_true, y_pred, average="macro")
result["precision (macro)"] = float(res)
if self.use_recall:
res = recall_score(y_true, y_pred, average="weighted")
result["recall (weighted)"] = float(res)

res = recall_score(y_true, y_pred, average="micro")
result["recall (micro)"] = float(res)

res = recall_score(y_true, y_pred, average="macro")
result["recall (macro)"] = float(res)

if self.use_geometric_mean:
res = np.sqrt(recall_score(y_true, y_pred, average="weighted") * precision_score(y_true, y_pred, average="weighted"))
result["geometric mean"] = float(res)

if self.use_confusion_matrix:
res = confusion_matrix(y_true, y_pred)
Expand Down
21 changes: 17 additions & 4 deletions src/librep/transforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
from .autocorrelation import *
from .convaelstm import *
from .dimal import *
from .fft import *
from .filter import *
from .ica import *
from .isomap import *
from .kernel_pca import *
from .lle import *
from .lstm import *
from .pca import *
from .removeFrequencies import *
from .resampler import *
from .umap import *
from .tsne import *
from .autocorrelation import *
from .reshaper import *
from .simclr_full import *
from .simclr_linear import *
from .simclr import *
from .spectrogram import *
from .stats import *
from .removeFrequencies import *
from .topo_ae import *
from .tsne import *
from .umap import *
2 changes: 2 additions & 0 deletions src/librep/transforms/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def transform(self, X: ArrayLike) -> ArrayLike:
data = fftpack.fft(data)
if self.absolute:
data = np.abs(data)
else:
data = np.real(data)
if self.centered:
data = data[:len(data)//2]
datas.append(data)
Expand Down
3 changes: 3 additions & 0 deletions src/librep/transforms/ica.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sklearn.decomposition import FastICA as reducer

FastICA = reducer
3 changes: 3 additions & 0 deletions src/librep/transforms/isomap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sklearn.manifold import Isomap as reducer

Isomap = reducer
3 changes: 3 additions & 0 deletions src/librep/transforms/kernel_pca.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sklearn.decomposition import KernelPCA as reducer

KernelPCA = reducer
3 changes: 3 additions & 0 deletions src/librep/transforms/lle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sklearn.manifold import LocallyLinearEmbedding as reducer

LocallyLinearEmbedding = reducer
Loading