Skip to content

Instantly share code, notes, and snippets.

@bjorskog
bjorskog / Makefile
Created November 23, 2020 21:25
Makefile for ML-models
.PHONY: help lint run
# Makefile variables
VENV_NAME:=venv
PYTHON=${VENV_NAME}/bin/python3
# Include your variables here
RANDOM_SEED:=42
NUM_EPOCHS:=15
INPUT_DIM:=784
@bjorskog
bjorskog / gitignore
Created January 31, 2020 11:40
My gitignore file
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@bjorskog
bjorskog / luigi_mock_test.py
Created January 17, 2020 06:15
Example of using MockTest for testing pipelines in Luigi. Will not write tasks to disk, only memory. Simplifies runs a lot during testing.
import os
import luigi
import pandas as pd
from luigi.mock import MockTarget
class MopedExport(luigi.ExternalTask):
""" source data """
@bjorskog
bjorskog / moped_data.txt
Last active April 28, 2017 08:11
Sample moped data set.
OwnerAge Gender Zone McClass VehicleAge BonusClass Duration NoClaims ClaimCost
0 M 1 4 12 1 0.1753 0 0
4 M 3 6 9 1 0.0000 0 0
5 K 3 3 18 1 0.4548 0 0
5 K 4 1 25 1 0.1726 0 0
6 K 2 1 26 1 0.1808 0 0
9 K 3 3 8 1 0.5425 0 0
9 K 4 3 6 1 0.0000 0 0
9 M 4 4 20 1 0.5041 0 0
10 M 2 3 16 1 0.1507 0 0
@bjorskog
bjorskog / statnett.py
Created November 25, 2016 10:27
Loading production and consumption data from Statnett
"""
Extracting various figures from Statnett
"""
import requests
import datetime
import pprint
@bjorskog
bjorskog / svm_rsi_trend.R
Created December 29, 2015 16:12 — forked from Inpirical-Coder/svm_rsi_trend.R
Trains and tests SVM on two features (relative strength index and trend over x observations)
# Some code to asses an SVM with a two-dimensional feature space:
# trend (price - simple moving average) and relative strength index.
# The code is an adaptation of the code found in the following linkedin post:
# "Trading the RSI using a Support Vector Machine"
# "https://www.linkedin.com/pulse/article/20141103165037-172934333-trading-the-rsi-using-a-support-vector-machine"
# Settings
sma.window = 50 # Number of observations in simple moving average.
rsi.window = 3 # Number of observation in relative strength index (RSI)
#!/usr/bin/env python
import csv
import datetime
outfile = "profile_20150801.csv"
startdate = datetime.datetime(2015, 1, 1, 0)
#startdate = datetime.datetime.now()
enddate = datetime.datetime(2019, 1, 1)
hour = datetime.timedelta(hours=1)
@bjorskog
bjorskog / kalman.py
Created September 9, 2014 09:04
Implementation of a Kalman-filter
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 09 10:59:11 2014
@author: bjorskog
"""
import numpy as np
import pandas as pd
@bjorskog
bjorskog / MongoStore.py
Last active August 29, 2015 14:02
Prototype for an API for storing time series to MongoDB. Should also take care of versioning of the time series in the future.
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 17 17:59:59 2014
@author: bjorskog
"""
from datetime import datetime
from bson.objectid import ObjectId
from pymongo import MongoClient
@bjorskog
bjorskog / aservice.py
Created January 14, 2014 12:26
Prototype for a windows service written i Python.
import win32service
import win32serviceutil
import win32api
import win32con
import win32event
import win32evtlogutil
import os
class aservice(win32serviceutil.ServiceFramework):