Skip to content

Instantly share code, notes, and snippets.

View mindis's full-sized avatar

Mindaugas Zickus mindis

  • Marks and Spencer
  • London, UK
  • X @MindisZ
View GitHub Profile
@twiecki
twiecki / GLM-hierarchical-jax.ipynb
Last active September 7, 2022 23:21
notebooks/GLM-hierarchical.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import pandas as pd
import tensorflow as tf
import dask.dataframe as dd
from dask.distributed import Client, LocalCluster
from tensorflow.python.saved_model import loader
def encode_factory(sess, export_path:str):
"""Loads TF SavedModel and returns a callable"""
# How to use TimeBasedCV
data_for_modeling=pd.read_csv('data.csv', parse_dates=['record_date'])
tscv = TimeBasedCV(train_period=30,
test_period=7,
freq='days')
for train_index, test_index in tscv.split(data_for_modeling,
validation_split_date=datetime.date(2019,2,1), date_column='record_date'):
print(train_index, test_index)
# get number of splits
import pandas as pd
import datetime
from datetime import datetime as dt
from dateutil.relativedelta import *
class TimeBasedCV(object):
'''
Parameters
----------
train_period: int
@c-bata
c-bata / lightgbm_rfe.py
Last active June 12, 2024 19:34
Recursive Feature Elimination for LightGBM. This class accepts missing values and Optuna LightGBM tuner.
import numpy as np
import pandas as pd
#import lightgbm as lgb
from optuna.integration import lightgbm as lgb
from sklearn.model_selection import train_test_split
from sklearn.utils import check_X_y, safe_sqr
from sklearn.feature_selection.base import SelectorMixin
from lightgbm import Booster
@eggie5
eggie5 / clr.py
Created November 11, 2019 22:00
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.ops import math_ops
from tensorflow.python.eager import context
def cyclic_learning_rate(global_step,
learning_rate=0.01,
max_lr=0.1,
step_size=20.,
gamma=0.99994,
@piyueh
piyueh / tf_keras_tfp_lbfgs.py
Last active April 28, 2025 04:09
Optimize TensorFlow & Keras models with L-BFGS from TensorFlow Probability
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 Pi-Yueh Chuang <pychuang@gwu.edu>
#
# Distributed under terms of the MIT license.
"""An example of using tfp.optimizer.lbfgs_minimize to optimize a TensorFlow model.
import pandas as pd
import numpy as np
import patsy
import tensorflow as tf
class SleepReg(tf.Module):
def __init__(self, sleepdata_path):
"""Initializing tensorflow variables and other necessary matrices"""
# These two TensorFlow variables show up in the trainable_variables
{
"type" : "record",
"name" : "TrainingExample",
"namespace" : "com.linkedin.metronome.avro.generated",
"fields" : [ {
"name" : "uid",
"type" : [ "null", "string", "long", "int" ],
"doc" : "a unique id for the training event",
"default" : null
}, {
@tgsmith61591
tgsmith61591 / ranking.py
Last active March 21, 2024 06:36
Ranking metrics for recommender systems
# -*- coding: utf-8 -*-
#
# Author: Taylor G Smith
#
# Recommender system ranking metrics derived from Spark source for use with
# Python-based recommender libraries (i.e., implicit,
# http://github.com/benfred/implicit/). These metrics are derived from the
# original Spark Scala source code for recommender metrics.
# https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/mllib/evaluation/RankingMetrics.scala