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
import pandas as pd
import datetime
from datetime import datetime as dt
from dateutil.relativedelta import *
class TimeBasedCV(object):
'''
Parameters
----------
train_period: int
# 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
@mindis
mindis / tf_keras_tfp_lbfgs.py
Created April 6, 2020 16:07 — forked from piyueh/tf_keras_tfp_lbfgs.py
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 <[email protected]>
#
# Distributed under terms of the MIT license.
"""An example of using tfp.optimizer.lbfgs_minimize to optimize a TensorFlow model.
@mindis
mindis / verify_tfrecords.py
Created April 3, 2020 08:24 — forked from LeegleechN/verify_tfrecords.py
Check TFRecords
"""Checks if a set of TFRecords appear to be valid.
Specifically, this checks whether the provided record sizes are consistent and
that the file does not end in the middle of a record. It does not verify the
CRCs.
"""
import struct
import tensorflow as tf
from tensorflow import app
@mindis
mindis / clr.py
Created April 3, 2020 08:24 — forked from eggie5/clr.py
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,
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"""
@mindis
mindis / sparse_multiclass_numba.py
Created January 27, 2020 14:58 — forked from mblondel/sparse_multiclass_numba.py
Sparse Multiclass Classification in Numba!
"""
(C) August 2013, Mathieu Blondel
# License: BSD 3 clause
This is a Numba-based reimplementation of the block coordinate descent solver
(without line search) described in the paper:
Block Coordinate Descent Algorithms for Large-scale Sparse Multiclass
Classification. Mathieu Blondel, Kazuhiro Seki, and Kuniaki Uehara.
Machine Learning, May 2013.
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
@mindis
mindis / keras_explicit_MF.py
Created June 25, 2019 14:48
Keras Explicit Matrix Factorization for Missing Feature Imputation
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 22 10:31:23 2017
@author: SF
"""
import numpy as np
from keras.layers import Input
from keras.models import Model
@mindis
mindis / timeseries_cnn.py
Created May 1, 2019 13:31 — forked from jkleint/timeseries_cnn.py
Example of using Keras to implement a 1D convolutional neural network (CNN) for timeseries prediction.
#!/usr/bin/env python
"""
Example of using Keras to implement a 1D convolutional neural network (CNN) for timeseries prediction.
"""
from __future__ import print_function, division
import numpy as np
from keras.layers import Convolution1D, Dense, MaxPooling1D, Flatten
from keras.models import Sequential