Git Product home page Git Product logo

modeldag's Introduction

PyPI Documentation Status

modeldag

DataFrame generator through simple dictionary forming a direct acyclic graph (DAG)

Installation

pip install modeldag

Dependency

  • numpy
  • pandas
  • graphviz (optional, used for visualize)

Concept

Build a simple dictionary forming a DAG (this is the model) and call mdag = ModelDAG(model).

The model dictionary is a simple nested directory with the following format:

model = {key1 : {'func': func, 'kwargs': dict, 'as': None_str_list'},
         key2 : {'func': func, 'kwargs': dict, 'as': None_str_list'},
         ...
         }

ModelDAG will read this dictionary to create a pandas.DataFrame with each column called as (if given, key is used as name otherwise ). The dataframe columns are generated calling func(**kwargs).

The trick of modeldag is that you can use "@key1" in kwargs of key2 to use key1 generated values as input of key2 model. Furthermore modeldag will sort the input dict to make sure keys are drawn in the good order, so combine models are you wish !

Sharp start

Let's create variable "a" normally distributed N(mu=10, simga=2) and "a_err" a customed function (foo) that depends on "a"

import numpy as np
import modeldag

def foo(value, scale=0.05, floor=0.2):
    """ the quadratic sum between value*scale and floor """
    return np.sqrt( (value*scale)**2 + floor**2)


model = {"a": {"func": np.random.normal,
               "kwargs": {"loc":10, "scale":2}
              },
        "a_err": {"func": foo,
                  "kwargs": {"value":"@a"} # leaving other param unchanged
              }
        }

mdag = modeldag.ModelDAG(model)
mdag.visualize()

data = mdag.draw(1000)
data.head(3)
           a     a_err
0  14.054751  0.730644
1  13.500349  0.704023
2   9.713155  0.525227

modeldag's People

Contributors

mickaelrigault avatar

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.