|
| 1 | +# GSP-Py Interactive Notebooks |
| 2 | + |
| 3 | +This directory contains interactive [marimo](https://marimo.io/) notebooks demonstrating various features of GSP-Py. |
| 4 | + |
| 5 | +## Available Notebooks |
| 6 | + |
| 7 | +### 1. `sequence_example.py` |
| 8 | +Demonstrates the Sequence abstraction in GSP-Py: |
| 9 | +- Traditional dict-based output vs. Sequence objects |
| 10 | +- Accessing sequence properties |
| 11 | +- Filtering and analyzing sequences |
| 12 | +- Creating custom sequence objects |
| 13 | +- Pattern analysis and statistics |
| 14 | + |
| 15 | +### 2. `itemset_example.py` |
| 16 | +Shows how to use itemsets where multiple items occur together: |
| 17 | +- Flat vs. itemset sequences |
| 18 | +- Market basket analysis with itemsets |
| 19 | +- E-commerce click streams with concurrent actions |
| 20 | + |
| 21 | +### 3. `dataframe_example.py` |
| 22 | +Integration with Polars and Pandas DataFrames: |
| 23 | +- Polars DataFrame with grouped format |
| 24 | +- Pandas DataFrame with sequence format |
| 25 | +- Temporal mining with timestamps |
| 26 | + |
| 27 | +## Running Notebooks Locally |
| 28 | + |
| 29 | +### Prerequisites |
| 30 | + |
| 31 | +Install marimo and GSP-Py with dataframe support: |
| 32 | + |
| 33 | +```bash |
| 34 | +pip install marimo 'gsppy[dataframe]' |
| 35 | +``` |
| 36 | + |
| 37 | +### Running a Notebook |
| 38 | + |
| 39 | +To run a notebook interactively: |
| 40 | + |
| 41 | +```bash |
| 42 | +marimo edit sequence_example.py |
| 43 | +``` |
| 44 | + |
| 45 | +This opens the notebook in your browser where you can: |
| 46 | +- Modify code and see results update reactively |
| 47 | +- Experiment with different parameters |
| 48 | +- Save your changes |
| 49 | + |
| 50 | +### Running as a Script |
| 51 | + |
| 52 | +You can also run notebooks as regular Python scripts: |
| 53 | + |
| 54 | +```bash |
| 55 | +python sequence_example.py |
| 56 | +``` |
| 57 | + |
| 58 | +Or using marimo's run command for a read-only app: |
| 59 | + |
| 60 | +```bash |
| 61 | +marimo run sequence_example.py |
| 62 | +``` |
| 63 | + |
| 64 | +## Notebook Structure |
| 65 | + |
| 66 | +Marimo notebooks are: |
| 67 | +- **Pure Python files**: Easy to version control and review |
| 68 | +- **Reactive**: Changes propagate automatically through dependent cells |
| 69 | +- **Reproducible**: Execute deterministically every time |
| 70 | +- **Shareable**: Can be exported to HTML, PDF, or run as web apps |
| 71 | + |
| 72 | +Each notebook is structured with `@app.cell` decorators that define reactive cells. Variables defined in one cell are automatically available to dependent cells. |
| 73 | + |
| 74 | +## Exporting Notebooks |
| 75 | + |
| 76 | +To export a notebook to HTML for documentation: |
| 77 | + |
| 78 | +```bash |
| 79 | +marimo export html sequence_example.py -o sequence_example.html |
| 80 | +``` |
| 81 | + |
| 82 | +To export to Markdown: |
| 83 | + |
| 84 | +```bash |
| 85 | +marimo export md sequence_example.py -o sequence_example.md |
| 86 | +``` |
| 87 | + |
| 88 | +## Contributing |
| 89 | + |
| 90 | +When adding new notebooks: |
| 91 | + |
| 92 | +1. Create the notebook in this directory |
| 93 | +2. Test it with `marimo check your_notebook.py` |
| 94 | +3. Export to HTML: `marimo export html your_notebook.py -o ../docs/your_notebook.html --force` |
| 95 | +4. Add a link in `docs/examples.md` |
| 96 | +5. Update `mkdocs.yml` if adding a new documentation page |
| 97 | +6. Commit both the `.py` notebook and the `.html` export |
| 98 | + |
| 99 | +**Important:** When modifying existing notebooks, remember to regenerate the HTML export: |
| 100 | + |
| 101 | +```bash |
| 102 | +# After modifying a notebook |
| 103 | +marimo export html your_notebook.py -o ../docs/your_notebook.html --force |
| 104 | +git add notebooks/your_notebook.py docs/your_notebook.html |
| 105 | +``` |
| 106 | + |
| 107 | +This ensures the documentation stays in sync with the notebook source. |
| 108 | + |
| 109 | +## More Resources |
| 110 | + |
| 111 | +- [Marimo Documentation](https://docs.marimo.io/) |
| 112 | +- [GSP-Py Documentation](https://jacksonpradolima.github.io/gsp-py/) |
| 113 | +- [GSP-Py API Reference](https://jacksonpradolima.github.io/gsp-py/api.html) |
0 commit comments