Skip to content

Commit 5617cbb

Browse files
committed
How to run a simple example
1 parent 31b3d17 commit 5617cbb

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,54 @@ All the other functions contains functions used for the clustering.
77

88
## Dependencies
99
This code has been executed with `python3` with the library indicated in `requirements.txt`. Additionaly, it is necessary to have R installed with the library `conclust`.
10+
For setting up the environment:
11+
```
12+
conda create --name clustering
13+
conda install -f -y -q --name clustering -c conda-forge --file requirements.txt
14+
conda activate clustering
15+
pip install pmlb metric-learn==0.4.0 hyperopt
16+
```
1017

1118
## How to compare your method ?
1219
Import your library in `Experiments.ipynb` and select the algorithms that you want to run. The execution of the notebook saves all results in the result folder (indicated in `config.py` with the timestamp indicated when you run the experiments notebook). Copy this timestamp in the `dates` list in `Visualizations.ipynb` to compare the results (you can indicate several dates to compare methods computed at different time).
20+
21+
## How to run our model on your dataset ?
22+
23+
### Kernel Clustering
24+
#### Open your data and constraints
25+
```
26+
import pandas as pd
27+
import numpy as np
28+
29+
dname = 'data' # Data name - Used for saving kernels
30+
ncluster = 3 # Number cluster
31+
data = pd.read_csv(dname)
32+
constraint = np.full((len(data), len(data)), 1) # Constraint matrix : +1 if linked, -1 otherwise - Prefer coomatrix
33+
```
34+
35+
#### Create kernels
36+
```
37+
from models.kernel_opt import kernel_clustering
38+
from kernels.features import produce_kernels, normalize_and_check_kernels
39+
40+
kernels_name = ['rbf', 'sigmoid', 'polynomial',
41+
'laplacian', 'linear']
42+
kernel_args = {"normalize": "expectation",
43+
"check_method": "trivial",
44+
"clip": True}
45+
46+
names, kernels = produce_kernels(dname, kernels_name, data, n_jobs = n_jobs)
47+
names, kernels = normalize_and_check_kernels(names, kernels, ncluster, n_jobs = n_jobs, **kernel_args)
48+
```
49+
50+
#### Run Kmeans and opitmization
51+
```
52+
assignment = kernel_clustering(kernels, ncluster, constraint)
53+
```
54+
55+
### Use Mahalanobius
56+
```
57+
from models.mahalanobis import mahalanobis_bayes_clustering
58+
59+
assignment = mahalanobis_bayes_clustering(data, ncluster, constraint)
60+
```

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
numpy
2-
scikit-learn
2+
numba
3+
scikit-learn=0.20.4
34
seaborn
45
matplotlib
56
rpy2
6-
pmlb
77
GPyOpt
8-
metric-learn==0.4.0
8+
jupyter
9+
tqdm

0 commit comments

Comments
 (0)