Skip to content

Instantly share code, notes, and snippets.

@Sandy4321
Sandy4321 / quantreg_gradient.ipynb
Created May 25, 2023 21:16 — forked from avidale/quantreg_gradient.ipynb
quantreg_gradient.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Sandy4321
Sandy4321 / prefixspan.py
Created September 7, 2022 22:09 — forked from chuanconggao/prefixspan.py
The original minimal 15 lines implementation of PrefixSpan. Full library at https://github.com/chuanconggao/PrefixSpan-py.
from collections import defaultdict
def frequent_rec(patt, mdb):
results.append((len(mdb), patt))
occurs = defaultdict(list)
for (i, startpos) in mdb:
seq = db[i]
for j in range(startpos + 1, len(seq)):
l = occurs[seq[j]]
@Sandy4321
Sandy4321 / xgb_quantile_loss.py
Created January 18, 2022 22:01 — forked from Nikolay-Lysenko/xgb_quantile_loss.py
Customized loss function for quantile regression with XGBoost
import numpy as np
def xgb_quantile_eval(preds, dmatrix, quantile=0.2):
"""
Customized evaluational metric that equals
to quantile regression loss (also known as
pinball loss).
Quantile regression is regression that
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from nltk.stem import PorterStemmer
from nltk.tokenize import word_tokenize
import re
ps = PorterStemmer()
collection_file = './collectionandqueries/collection.tsv'
categories_file = './categories.tsv'
with open(categories_file) as categories:
categories_dict = dict()
@Sandy4321
Sandy4321 / nested-cv.py
Created July 27, 2021 17:50 — forked from betatim/nested-cv.py
Nested CV
from sklearn.datasets import load_iris
from matplotlib import pyplot as plt
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV, cross_val_score, KFold
from sklearn.model_selection import StratifiedShuffleSplit
from sklearn.model_selection import ShuffleSplit
import numpy as np
from scipy.stats import sem
def create_experiment(experiment_name, base_campaign_id, draft_id, split_percent=50, split_type='COOKIE'):
adwords_client = connect_to_adwords_api()
trial_service = adwords_client.GetService('TrialService', version='v201809')
trial = {
'draftId': draft_id,
'baseCampaignId': base_campaign_id,
'name': experiment_name,
'trafficSplitPercent': split_percent,
'trafficSplitType': split_type
}
import pandas as pd
def get_all_ad_groups_from_campaign(campaign_id):
adwords_client = connect_to_adwords_api()
ad_group_service = adwords_client.GetService('AdGroupService', version='v201809')
selector = {
'fields': ['Id', 'Name', 'Status','TargetCpa'],
'paging': {
'startIndex': str(0),
import pandas as pd
def get_all_ad_groups_from_campaign(campaign_id):
adwords_client = connect_to_adwords_api()
ad_group_service = adwords_client.GetService('AdGroupService', version='v201809')
selector = {
'fields': ['Id', 'Name', 'Status','TargetCpa'],
'paging': {
'startIndex': str(0),