From de5f2d6e6f6d658c71f49ca493008fa2a3ac55b0 Mon Sep 17 00:00:00 2001 From: Jorge Morgado Vega Date: Wed, 7 Jun 2023 14:10:34 -0400 Subject: [PATCH] Update readme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gustavo Viera López --- README.md | 85 +++++++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 3771db1..d8243b2 100644 --- a/README.md +++ b/README.md @@ -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/) \ No newline at end of file +Follow the guidlines from [pactus documentation](https://pactus.readthedocs.io/en/latest/)