From 53ed7c416a7dee0f47d0dfe96880d04939bece7e Mon Sep 17 00:00:00 2001 From: benheid Date: Mon, 12 Feb 2024 19:36:34 +0100 Subject: [PATCH 1/2] draft of getting_started notebook. --- .binder/Dockerfile | 22 +++++++ examples/getting_started.ipynb | 103 +++++++++++++++++++++++++++++++++ pyproject.toml | 5 ++ 3 files changed, 130 insertions(+) create mode 100644 .binder/Dockerfile create mode 100644 examples/getting_started.ipynb diff --git a/.binder/Dockerfile b/.binder/Dockerfile new file mode 100644 index 00000000..8932745f --- /dev/null +++ b/.binder/Dockerfile @@ -0,0 +1,22 @@ +# This Dockerfile is used to build sktime when launching binder. +# Find out more at: https://mybinder.readthedocs.io/en/latest/index.html + +FROM jupyter/scipy-notebook:python-3.11.6 +# Set up user to avoid running as root +ARG NB_USER +ARG NB_UID +ENV USER ${NB_USER} +ENV HOME /home/${NB_USER} + +# Binder will automatically clone the repo, but we need to make sure the +# contents of our repo are in the ${HOME} directory +COPY . ${HOME} +USER root +RUN chown -R ${NB_UID} ${HOME} + +# Switch user and directory +USER ${USER} +WORKDIR ${HOME} + +# Install extra requirements and sktime based on master branch +RUN pip install --upgrade pip --no-cache-dir && pip install .[binder] diff --git a/examples/getting_started.ipynb b/examples/getting_started.ipynb new file mode 100644 index 00000000..943ec17e --- /dev/null +++ b/examples/getting_started.ipynb @@ -0,0 +1,103 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Welcome to tsbootstrap\n", + "\n", + "`tsbootstrap` is a `sklearn` and `sktime` compatible library of bootstrapping algorithm for time series.\n", + "This notebook explains how you can start with tsbootstrap. \n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Getting started\n", + "`tsbootsrap` is following the [`sklearn` design principle](https://scikit-learn.org/stable/developers/develop.html). This means that there are mainly three steps of interaction of a bootstrapper:\n", + "1. Initiate the bootrapper\n", + "2. Fitting the bootstrapper\n", + "3. Transforming the data using the fitted bootstrapper" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this example, we use the moving block bootstrapper. Therefore, we instantiate the class. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from tsbootstrap import MovingBlockBootstrap, MovingBlockBootstrapConfig\n", + "\n", + "bootstrapper = MovingBlockBootstrap(block_length=10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "After the instantiation, we can fit the bootsrapper. Therefore, we load the airline passenger dataset using the dataset loading functionalities of sktime" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from sktime.datasets import load_airline\n", + "\n", + "y = load_airline()\n", + "\n", + "bootstrapper.fit(y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "After fitting the bootstrapper, we can use the bootstrapper to transform the data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "bootstrapper.transform(y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instead of calling first `fit` and `transform` afterwards, we can also use the shortcut: `fit_transform`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "bootstrapper.fit_transform(y)" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/pyproject.toml b/pyproject.toml index 3a8cccc4..995c30ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -237,3 +237,8 @@ exclude = [".venv/*", "tests/*", "docs/*", "build/*", "dist/*", "src/tsbootstrap [tool.coverage.run] source = ['src/'] omit = ['tests/*', '.venv/*'] + +binder = [ + "jupyter", + "sktime", +] From 6cdcc1de75ac4a003836dfbd93e50b6190d5b3d1 Mon Sep 17 00:00:00 2001 From: benheid Date: Mon, 12 Feb 2024 20:12:23 +0100 Subject: [PATCH 2/2] Fix pyproject --- pyproject.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 995c30ba..a37f2e36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,6 +71,11 @@ dev = [ "pytest-cov", ] +binder = [ + "jupyter", + "sktime", +] + [tool.poetry.dev-dependencies] # Add your dev dependencies here, e.g. black = "~23.10" @@ -237,8 +242,3 @@ exclude = [".venv/*", "tests/*", "docs/*", "build/*", "dist/*", "src/tsbootstrap [tool.coverage.run] source = ['src/'] omit = ['tests/*', '.venv/*'] - -binder = [ - "jupyter", - "sktime", -]