Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
Co-authored-by: Gustavo Viera López <[email protected]>
  • Loading branch information
jmorgadov and gvieralopez committed Jun 7, 2023
1 parent e002835 commit de5f2d6
Showing 1 changed file with 29 additions and 56 deletions.
85 changes: 29 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,82 +29,55 @@ pip install pactus

## Getting started

This is quick example of how to test a Random Forest classifier on a preprocessed
version of the GeoLife dataset:
This is quick example of how to test a Random Forest classifier on the Animals dataset:

```python
from pactus import Dataset, featurizers
from pactus.models import RandomForestModel

# Load Dataset
dataset = Dataset.geolife()

# Select the desired features to be extracted from the trajectories
featurizer = featurizers.UniversalFeaturizer()

# Defining the model
model = RandomForestModel(
featurizer=featurizer,
max_features=16,
n_estimators=200,
bootstrap=False,
random_state=SEED,
warm_start=True,
n_jobs=6,
)

# Preprocess the dataset and split it into train and test sets
use_classes = {"car", "taxi-bus", "walk", "bike", "subway", "train"}
train, test = (
# Remove short and pourly time sampled trajectories
dataset.filter(lambda traj, _: len(traj) > 10 and traj.dt < 8)
# Join "taxi" and "bus" into "taxi-bus"
.map(lambda _, label: (_, "taxi-bus" if label in ("bus", "taxi") else label))
# Only use the classes defined in use_classes
.filter(lambda _, label: label in use_classes)
# Split the dataset into train and test
.split(train_size=0.7, random_state=SEED)
)

# Train the model
model.train(data=train, cross_validation=5)

# Evaluate the model on a test dataset
evaluation = model.evaluate(test)
# Load dataset
dataset = Dataset.animals()

# Split data into train and test subsets
train, test = dataset.split(0.9)

# Convert trajectories into feature vectors
ft = featurizers.UniversalFeaturizer()

# Build and train the model
model = RandomForestModel(featurizer=ft)
model.train(train, cross_validation=5)

# Show the evaluation results
# Evaluate the results on the test subset
evaluation = model.evaluate(test)
evaluation.show()
```

It should output the evaluation results as:
It should output evaluation results similar to:

```
```text
General statistics:
Accuracy: 0.913
F1-score: 0.892
Mean precision: 0.910
Mean recall: 0.877
Accuracy: 0.962
F1-score: 0.951
Mean precision: 0.976
Mean recall: 0.933
Confusion matrix:
bike car subway taxi-bus train walk precision
======================================================================
89.83 0.56 0.74 1.29 0.0 1.41 94.03
0.25 79.1 0.74 1.94 0.0 0.11 90.32
0.0 0.56 82.35 1.46 0.0 0.22 90.32
2.48 18.08 10.29 91.42 12.12 2.5 87.19
0.0 0.56 0.0 0.32 87.88 0.0 90.62
7.44 1.13 5.88 3.56 0.0 95.76 93.43
----------------------------------------------------------------------
89.83 79.1 82.35 91.42 87.88 95.76
Cattle Deer Elk precision
================================
100.0 0.0 0.0 100.0
0.0 80.0 0.0 100.0
0.0 20.0 100.0 92.86
--------------------------------
100.0 80.0 100.0
```

## Available datasets

See the whole [list of datasets](https://github.com/yupidevs/trajectory-datasets) compatible with pactus


## Contributing

Follow the guidlines from [pactus documentation](https://pactus.readthedocs.io/en/latest/)
Follow the guidlines from [pactus documentation](https://pactus.readthedocs.io/en/latest/)

0 comments on commit de5f2d6

Please sign in to comment.