Skip to content

Commit

Permalink
Merge pull request #40 from awslabs/v0.2.0
Browse files Browse the repository at this point in the history
This Version update will provide a predict method
  • Loading branch information
momonga-ml authored Dec 3, 2023
2 parents 7a680ba + 3487a82 commit 658c2b0
Show file tree
Hide file tree
Showing 16 changed files with 673 additions and 145 deletions.
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repos:
- id: requirements-txt-fixer
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: check-merge-conflict
- id: check-added-large-files
- id: check-case-conflict
- repo: https://github.com/psf/black
# workaround for black
# see: https://github.com/psf/black/issues/2493#issuecomment-1081987650
Expand All @@ -34,7 +37,7 @@ repos:
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.7.1
hooks:
- id: mypy
exclude: ^testing/resources/
Expand All @@ -44,7 +47,7 @@ repos:
- id: python-bandit-vulnerability-check
args: [--skip, "B101", --recursive, denseclus]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.5
rev: v0.1.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -64,7 +67,7 @@ repos:
hooks:
- id: pyupgrade
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
rev: 1.7.1
hooks:
- id: nbqa-pyupgrade
args: ["--py37-plus"]
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,42 @@ All preprocessing and extraction are done under the hood, just call fit and then
from denseclus import DenseClus
from denseclus.utils import make_dataframe

df = make_dataframe()

clf = DenseClus()
df = make_dataframe()
clf = DenseClus(df)
clf.fit(df)

print(clf.score())
scores = clf.score()
print(scores[0:10])
```


## Usage

### Prediction

DenseClus uses a `predict` method whhne `umap_combine_method` is set to `ensemble`.
Results are return in 2d array with the first part being the labels and the second part the probabilities.

```python
from denseclus import DenseClus
from denseclus.utils import make_dataframe

RANDOM_STATE = 10

df = make_dataframe(random_state=RANDOM_STATE)
train = df.sample(frac=0.8, random_state=RANDOM_STATE)
test = df.drop(train.index)
clf = DenseClus(random_state=RANDOM_STATE, umap_combine_method='ensemble')
clf.fit(train)

predictions = clf.predict(test)
print(predictions) # labels, probabilities
```


### On Combination Method

For a slower but more **stable** results select `intersection_union_mapper` to combine embedding layers via a third UMAP, which will provide equal weight to both numerics and categoriel columns. By default, you are setting the random seed which eliminates the ability for UMAP to run in parallel but will help circumevent some of [the randomness](https://umap-learn.readthedocs.io/en/latest/reproducibility.html) of the algorithm.

```python
Expand All @@ -51,10 +77,11 @@ clf = DenseClus(
)
```


### Advanced Usage

For advanced users, it's possible to select more fine-grained control of the underlying algorithms by passing
dictionaries into `DenseClus` class.
dictionaries into `DenseClus` class for either UMAP or HDBSCAN.

For example:
```python
Expand Down
Loading

0 comments on commit 658c2b0

Please sign in to comment.