This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sys | |
from google_auth_oauthlib.flow import InstalledAppFlow | |
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError | |
DEFAULT_CLIENT_ID = 'YOUR CLIENT ID OF YOUR APP CREATED @ GOOGLE API CENTER' | |
DEFAULT_CLIENT_SECRET = 'YOUR CLIENT SECRET OF YOUR APP CREATED @ GOOGLE API CENTER' | |
# The AdWords API OAuth2 scope. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Copyright (C) Lyla Yang - All Rights Reserved | |
Unauthorized copying of this file, via any medium is strictly prohibited | |
Proprietary and confidential | |
Written by Lyla Yang <https://www.linkedin.com/in/lyla-yang-aa850080/>, May 2019 | |
""" | |
""" | |
Reference of field attributes | |
https://developers.google.com/adwords/api/docs/appendix/reports#field-attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Refrence https://github.com/lylayang/facebook-python-ads-sdk | |
''' | |
from facebook_business.api import FacebookAdsApi | |
from facebook_business.adobjects.adaccount import AdAccount | |
from facebook_business.adobjects.adaccountuser import AdAccountUser | |
# Initialize a new Session and instantiate an API object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from statsmodels.stats.proportion import proportions_ztest | |
import pandas as pd | |
import numpy as np | |
conversions = np.array([486, 527]) | |
clicks = np.array([5000, 5000]) | |
zscore, pvalue = proportions_ztest(conversions, clicks, alternative = 'two-sided') | |
print('zscore = {:.4f}, pvalue = {:.4f}'.format(zscore, pvalue)) | |
# [output]: zscore = -1.3589, pvalue = 0.1742 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.stats import ttest_ind | |
import numpy as np | |
order_value_control_group=[32, 34, 29, 22, 39, 38, 37, 38, 36, 30, 26, 22, 22] | |
order_value_experimental_group=[40, 39, 30, 22, 39, 38, 37, 38, 36, 50, 26, 22, 49] | |
AOV_control_group=int(np.mean(order_value_control_group)) | |
AOV_experimental_group=int(np.mean(order_value_experimental_group)) | |
print('Average Order Value of Control Group: $', AOV_control_group) | |
print('Average Order Value of Experiment Group: $', AOV_experimental_group) | |
tscore, pval=ttest_ind(order_value_control_group, order_value_experimental_group) | |
print('t-score:', round(tscore,3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.stats.proportion as proportion | |
import numpy as np | |
converted = np.array([486, 527]) | |
clicks = np.array([5000, 5000]) | |
chisq, pvalue, table = proportion.proportions_chisquare(converted, clicks) | |
print('chisq =%.3f, pvalue = %.3f'%(chisq, pvalue)) | |
print("Contingency Table:") | |
print(table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy.stats as stats | |
from scipy.stats import chi2 | |
ob_table = np.array([[4514, 486], [4473, 527]]) | |
result = stats.chi2_contingency(ob_table, correction = False) # correction = False due to df=1 | |
chisq, pvalue = result[:2] | |
print('chisq = {}, pvalue = {}'.format(chisq, pvalue)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.stats import mannwhitneyu | |
sample1=[32, 34, 29, 39, 38, 37, 38, 36, 30, 26] | |
sample2=[40, 34, 30, 39, 38, 37, 38, 36, 50, 49] | |
stat, pvalue=mannwhitneyu(sample1, sample2) | |
print('statistics=%.3f, p=%.5f'%(stat,pvalue)) | |
alpha=0.05 | |
if pvalue> alpha: | |
print('Two Groups are from the Same distribution(fail to reject H0) under alpha=0.05') | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.stats.api as sms | |
baseline_cvr=0.1 | |
alpha=0.05 | |
power=0.8 | |
mini_diff=0.1*baseline_cvr | |
effect_size=sms.proportion_effectsize(baseline_cvr, baseline_cvr+mini_diff) | |
sample_size=sms.NormalIndPower().solve_power(effect_size=effect_size, power=power, alpha=alpha, ratio=1) | |
print('Required sample size ~ {0:.1f}'.format(sample_size) + ' per group') | |
#Output: | |
#Required sample size ~ 14744.1 per group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.stats.api as sms | |
effect_size = 0.1 | |
alpha = 0.05 # significance level | |
power = 0.8 | |
sample_size = sms.TTestIndPower().solve_power(effect_size = effect_size, power = power, alpha = alpha) | |
print('Required sample size ~ {0:.1f}'.format(sample_size) + ' per group') | |
#Output: | |
#Required sample size ~ 1570.7 per group |
OlderNewer