{"id":13710079,"url":"https://github.com/jmwoloso/pychattr","last_synced_at":"2025-05-06T18:33:56.749Z","repository":{"id":62579241,"uuid":"140499538","full_name":"jmwoloso/pychattr","owner":"jmwoloso","description":"Python Channel Attribution (pychattr) - A Python implementation of the excellent R ChannelAttribution library","archived":false,"fork":false,"pushed_at":"2022-09-05T20:29:08.000Z","size":2185,"stargazers_count":57,"open_issues_count":6,"forks_count":22,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-09-26T21:36:26.331Z","etag":null,"topics":["channel-attribution","data-analysis","data-science","machine-learning","python","python-channel-attribution","rpy2","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmwoloso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-11T00:01:31.000Z","updated_at":"2024-08-21T10:47:08.000Z","dependencies_parsed_at":"2022-11-03T21:00:41.035Z","dependency_job_id":null,"html_url":"https://github.com/jmwoloso/pychattr","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmwoloso%2Fpychattr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmwoloso%2Fpychattr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmwoloso%2Fpychattr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmwoloso%2Fpychattr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmwoloso","download_url":"https://codeload.github.com/jmwoloso/pychattr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224521537,"owners_count":17325251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["channel-attribution","data-analysis","data-science","machine-learning","python","python-channel-attribution","rpy2","wrapper"],"created_at":"2024-08-02T23:00:51.585Z","updated_at":"2024-11-13T20:31:03.505Z","avatar_url":"https://github.com/jmwoloso.png","language":"Python","funding_links":[],"categories":["Attribution"],"sub_categories":[],"readme":"# README\n\nThis is a Python implementation based on the ChannelAttribution package in R developed by Davide Altomare and David Loris.\n\nhttps://cran.r-project.org/web/packages/ChannelAttribution/ChannelAttribution.pdf\n\n**Please Note:** The authors of the original R library now also provide a python implementation of [ChannelAttribution](https://pypi.org/project/ChannelAttribution/) which you should probably use instead of my implmentation since theirs has additional features not available in this package.\n\n\n\n# Installation\n```pip install pychattr```\n\n\n# Markov Model\n```\nimport pandas as pd\nfrom pychattr.channel_attribution import MarkovModel\n\ndata = {\n    \"path\": [\n        \"A \u003e\u003e\u003e B \u003e\u003e\u003e A \u003e\u003e\u003e B \u003e\u003e\u003e B \u003e\u003e\u003e A\",\n        \"A \u003e\u003e\u003e B \u003e\u003e\u003e B \u003e\u003e\u003e A \u003e\u003e\u003e A\",\n        \"A \u003e\u003e\u003e A\"\n    ],\n    \"conversions\": [1, 1, 1],\n    \"revenue\": [1, 1, 1],\n    \"cost\": [1, 1, 1]\n}\n\ndf = pd.DataFrame(data)\n\npath_feature=\"path\"\nconversion_feature=\"conversions\"\nnull_feature=None\nrevenue_feature=\"revenue\"\ncost_feature=\"cost\"\nseparator=\"\u003e\u003e\u003e\"\nk_order=1\nn_simulations=10000\nmax_steps=None\nreturn_transition_probs=True\nrandom_state=26\n\n# instantiate the model\nmm = MarkovModel(path_feature=path_feature,\n                 conversion_feature=conversion_feature,\n                 null_feature=null_feature,\n                 revenue_feature=revenue_feature,\n                 cost_feature=cost_feature,\n                 separator=separator,\n                 k_order=k_order,\n                 n_simulations=n_simulations,\n                 max_steps=max_steps,\n                 return_transition_probs=return_transition_probs,\n                 random_state=random_state)\n\n# fit the model\nmm.fit(df)\n```\n\n```\n# view the simulation results\nprint(mm.attribution_model_)\n```\n```\n  channel_name  total_conversions\n0            A           1.991106\n1            B           1.008894\n```\n\n```\n# view the transition matrix\nprint(mm.transition_matrix_)\n```\n```\n  channel_from    channel_to  transition_probability\n0      (start)             A                     1.0\n1            A             B                     0.5\n2            A  (conversion)                     0.5\n3            B             A                     1.0\n```\n\n```\n# view the removal effects\nprint(mm.removal_effects_)\n```\n\n```\n  channel_name  removal_effect\n0            A          1.0000\n1            B          0.5067\n```\n\n\n\n# Heuristic Model\n```\nimport pandas as pd\nfrom pychattr.channel_attribution import HeuristicModel\n\ndata = {\n    \"path\": [\n        \"A \u003e\u003e\u003e B \u003e\u003e\u003e A \u003e\u003e\u003e B \u003e\u003e\u003e B \u003e\u003e\u003e A\",\n        \"A \u003e\u003e\u003e B \u003e\u003e\u003e B \u003e\u003e\u003e A \u003e\u003e\u003e A\",\n        \"A \u003e\u003e\u003e A\"\n    ],\n    \"conversions\": [1, 1, 1],\n    \"revenue\": [1, 1, 1],\n    \"cost\": [1, 1, 1]\n}\n\ndf = pd.DataFrame(data)\n\npath_feature=\"path\"\nconversion_feature=\"conversions\"\nnull_feature=None\nrevenue_feature=\"revenue\"\ncost_feature=\"cost\"\nseparator=\"\u003e\u003e\u003e\"\nfirst_touch=True\nlast_touch=True\nlinear_touch=True\nensemble_results=True\n\n# instantiate the model\nhm = HeuristicModel(path_feature=path_feature,\n                    conversion_feature=conversion_feature,\n                    null_feature=null_feature,\n                    revenue_feature=revenue_feature,\n                    cost_feature=cost_feature,\n                    separator=separator,\n                    first_touch=first_touch,\n                    last_touch=last_touch,\n                    linear_touch=linear_touch,\n                    ensemble_results=ensemble_results)\n\n# fit the model\nhm.fit(df)\n```\n\n```\n# view the heuristic results\nprint(hm.attribution_model_)\n```\n```\n  channel  first_touch_conversions  ...  ensemble_revenue  ensemble_cost\n0       A                      3.0  ...               8.1            5.1\n1       B                      0.0  ...               0.9            0.9\n[2 rows x 13 columns]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmwoloso%2Fpychattr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmwoloso%2Fpychattr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmwoloso%2Fpychattr/lists"}