Giter Site home page Giter Site logo

nikolaismolin / pychattr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jmwoloso/pychattr

0.0 1.0 0.0 2.18 MB

Python Channel Attribution (pychattr) - A Python implementation of the excellent R ChannelAttribution library

License: GNU General Public License v3.0

Python 100.00%

pychattr's Introduction

README

This is a Python implementation based on the ChannelAttribution package in R developed by Davide Altomare and David Loris.

https://cran.r-project.org/web/packages/ChannelAttribution/ChannelAttribution.pdf

Installation

pip install pychattr

Markov Model

import pandas as pd
from pychattr.channel_attribution import MarkovModel

data = {
    "path": [
        "A >>> B >>> A >>> B >>> B >>> A",
        "A >>> B >>> B >>> A >>> A",
        "A >>> A"
    ],
    "conversions": [1, 1, 1],
    "revenue": [1, 1, 1],
    "cost": [1, 1, 1]
}

df = pd.DataFrame(data)

path_feature="path"
conversion_feature="conversions"
null_feature=None
revenue_feature="revenue"
cost_feature="cost"
separator=">>>"
k_order=1
n_simulations=10000
max_steps=None
return_transition_probs=True
random_state=26

# instantiate the model
mm = MarkovModel(path_feature=path_feature,
                 conversion_feature=conversion_feature,
                 null_feature=null_feature,
                 revenue_feature=revenue_feature,
                 cost_feature=cost_feature,
                 separator=separator,
                 k_order=k_order,
                 n_simulations=n_simulations,
                 max_steps=max_steps,
                 return_transition_probs=return_transition_probs,
                 random_state=random_state)

# fit the model
mm.fit(df)
# view the simulation results
print(mm.attribution_model_)
  channel_name  total_conversions
0            A           1.991106
1            B           1.008894
# view the transition matrix
print(mm.transition_matrix_)
  channel_from    channel_to  transition_probability
0      (start)             A                     1.0
1            A             B                     0.5
2            A  (conversion)                     0.5
3            B             A                     1.0
# view the removal effects
print(mm.removal_effects_)
  channel_name  removal_effect
0            A          1.0000
1            B          0.5067

Heuristic Model

import pandas as pd
from pychattr.channel_attribution import HeuristicModel

data = {
    "path": [
        "A >>> B >>> A >>> B >>> B >>> A",
        "A >>> B >>> B >>> A >>> A",
        "A >>> A"
    ],
    "conversions": [1, 1, 1],
    "revenue": [1, 1, 1],
    "cost": [1, 1, 1]
}

df = pd.DataFrame(data)

path_feature="path"
conversion_feature="conversions"
null_feature=None
revenue_feature="revenue"
cost_feature="cost"
separator=">>>"
first_touch=True
last_touch=True
linear_touch=True
ensemble_results=True

# instantiate the model
hm = HeuristicModel(path_feature=path_feature,
                    conversion_feature=conversion_feature,
                    null_feature=null_feature,
                    revenue_feature=revenue_feature,
                    cost_feature=cost_feature,
                    separator=separator,
                    first_touch=first_touch,
                    last_touch=last_touch,
                    linear_touch=linear_touch,
                    ensemble_results=ensemble_results)

# fit the model
hm.fit(df)
# view the heuristic results
print(hm.attribution_model_)
  channel  first_touch_conversions  ...  ensemble_revenue  ensemble_cost
0       A                      3.0  ...               8.1            5.1
1       B                      0.0  ...               0.9            0.9
[2 rows x 13 columns]

pychattr's People

Contributors

jmwoloso avatar mjaeugster-avira avatar smilypie1989 avatar

Watchers

 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.