Giter VIP home page Giter VIP logo

Comments (1)

Julian-J-S avatar Julian-J-S commented on August 22, 2024

oh yeah, this is tricky 🤔. The "problem" is only at the start of the window

another easy example:

pl.DataFrame({"x": [1, 2, 3, 4]}).with_columns(
    without_weight=pl.col("x").rolling_mean(
        window_size=2,
        min_periods=0,
    ),
    with_weight_50_50=pl.col("x").rolling_mean(
        window_size=2,
        min_periods=0,
        weights=[0.5, 0.5],
    ),
    with_weight_20_80=pl.col("x").rolling_mean(
        window_size=2,
        min_periods=0,
        weights=[0.2, 0.8],
    ),
)

# shape: (4, 4)
# ┌─────┬────────────────┬───────────────────┬───────────────────┐
# │ x   ┆ without_weight ┆ with_weight_50_50 ┆ with_weight_20_80 │
# │ --- ┆ ---            ┆ ---               ┆ ---               │
# │ i64 ┆ f64            ┆ f64               ┆ f64               │
# ╞═════╪════════════════╪═══════════════════╪═══════════════════╡
# │ 1   ┆ 1.0            ┆ 0.5               ┆ 0.2               │ 🤔  window [1]
# │ 2   ┆ 1.5            ┆ 1.5               ┆ 1.8               │ ✅  window [1, 2]
# │ 3   ┆ 2.5            ┆ 2.5               ┆ 2.8               │ ✅ 
# │ 4   ┆ 3.5            ┆ 3.5               ┆ 3.8               │ ✅ 
# └─────┴────────────────┴───────────────────┴───────────────────┘

First window is only [1]

  • without weights: knows that this window has only length of 1 and divides by 1 ✅
  • with weights: multiplies by weight without considering missing weights (should always add to 100%?!) 🤔

Not sure if this is a bug or intended behaviour and requires more documentation.
But one can surely argue that the 50/50 weighted mean of 1 and nothing else is still 1 and not 0.5

from polars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.