I made a python library to do rolling rank

rollingrank

I made a python library called rollingrank that calculates the rank in the rolling window, so I will introduce it. Please use it with kaggle. Please report a bug on github issue.

Repository https://github.com/contribu/rollingrank

background

  1. I want to solve the problem of time series prediction with kaggle etc.
  2. I want to use the ranking in the rolling window as a feature.
  3. I couldn't find a python library to do that.
  4. An implementation in pandas was found but slow (https://github.com/pandas-dev/pandas/issues/9481)

In the problem I was solving Using the ranking in the rolling window as a feature was the key to achieving generalization performance. I think the point is that the distribution is not biased depending on the time.

While it seems to be useful (I don't know if it's useful in general because I only know my case) I don't see much in the kaggle area.

The reason may be that it is not easy to use. You can easily use the rolling rank with this library, so why not use it for the problem you are solving now?

Installation

pip install rollingrank

How to use

import numpy as np
import rollingrank

#Entering a numpy array will return a numpy array of the same length.
x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
y = rollingrank.rollingrank(x, window=3)
print(y)
# [nan nan  2.  1.  0.  1.  2.]

#With pct,[0, 1]Will return with
y = rollingrank.rollingrank(x, window=3, pct=True)
print(y)
# [nan nan 1.  0.5 0.  0.5 1. ]

Customize ranking

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.rank.html

Of the methods defined in, you can use average, min, max, first by passing them with the method option.

Caution

I wanted to make something with O (n * log (w)) complexity, When I looked closely after implementing it, it was O (n * w). If you devise a balance tree, you should be able to make it O (n * log (w)). Someone please.

It seems good to modify something like the following. https://github.com/mpaland/avl_array

Personal notes

How to make a pip library: https://blog.amedama.jp/entry/packaging-python

rolling rank: https://github.com/pandas-dev/pandas/issues/9481

Pybind11 was convenient for linking with C ++.

Recommended Posts

I made a python library to do rolling rank
I made a library to easily read config files with Python
I made a library that adds docstring to a Python stub file.
I made a python text
I made a Python module to translate comment outs
I made a library to operate AWS CloudFormation stack from CUI (Python Fabric)
I made a Line-bot using Python!
I made my own Python library
I made a fortune with Python.
I made a daemon with Python
I made a package to filter time series with python
I made Othello to teach Python3 to children (4)
I made a payroll program in Python!
I made a character counter with Python
I created a Python library to call the LINE WORKS API
I made Othello to teach Python3 to children (2)
I want to build a Python environment
I want to do a full text search with elasticsearch + python
I made Othello to teach Python3 to children (5)
I made a script to display emoji
I made a Hex map with Python
After studying Python3, I made a Slackbot
I made a roguelike game with Python
I made Othello to teach Python3 to children (3)
I made Othello to teach Python3 to children (1)
I made a simple blackjack with Python
I made a Python wrapper library for docomo image recognition API.
I made a configuration file with Python
I made a library for actuarial science
I made a neuron simulator with Python
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
[Python] I made a decorator that doesn't seem to have any use.
I made a password generator to teach Python3 to children (bonus) * Completely remade
I made a tool to automatically browse multiple sites with Selenium (Python)
I made a web application in Python that converts Markdown to HTML
I tried to discriminate a 6-digit number with a number discrimination application made with python
I made a script in python to convert .md files to Scrapbox format
I made a library konoha that switches the tokenizer to a nice feeling
I made a program to check the size of a file in Python
I made a function to see the movement of a two-dimensional array (Python)
I want to do a monkey patch only partially safely in Python
I made a python dictionary file for Neocomplete
I want to do Dunnett's test in Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
[Python] What I did to do Unit Test
I want to create a window in Python
I made a Twitter fujoshi blocker with Python ①
I want to make a game with Python
[Python] I made a Youtube Downloader with Tkinter.
I made a tool to compile Hy natively
I made a tool to get new articles
I want to write to a file with Python
I made a Caesar cryptographic program in Python.
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a Python Qiita API wrapper "qiipy"
I made a Line Bot that uses Python to retrieve unread Gmail emails!
[Python] Deep Learning: I tried to implement deep learning (DBN, SDA) without using a library.
I made a module in C language to filter images loaded by Python