Skip to content

Instantly share code, notes, and snippets.

View alaiacano's full-sized avatar

Adam Laiacano alaiacano

  • Spotify
  • New Rochelle, NY
View GitHub Profile
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: mlflow-project-example
description: A collection of MLFlow experiments.
annotations:
mlflow/experiment: '1'
tags:
- machine-learning
spec:
@alaiacano
alaiacano / EpsilonGreedy.scala
Created January 25, 2017 18:39
Example of using Algebird to combine multi armed bandit tests.
import com.twitter.algebird._
import com.twitter.algebird.Operators._
import scala.util.Random
Random.setSeed(0L)
/**
* An "arm" represents an option in our A/B test.
*
* @param name Name of this option

Blink 182 and Green Day were and are still very popular bands. Therefore, they'll end up on a lot of playlists. Here are some genres where it would make sense to see them. I'll assign a distribution too, since obviously a band isn't limited to one kind of playlist.

So let's say Green Day is on 2,000 different playlists, broken down among these genres:

  • Punk - 35%
  • Rock - 20%
  • 90s - 20%
  • Alternative - 20%
  • Party - 5%
@alaiacano
alaiacano / complexunion.avdl
Created May 23, 2015 12:31
example of a complex avro union
record FirstType {
union { null, int } field1 = null;
union { null, int } field2 = null;
}
record SecondType {
union { null, long } someOtherField = null;
}
record MyAvroObjec {
// load the data and convert it to a Glass object.
val data: TypedPipe[Glass] = TextLine(args("input"))
.map{line => Glass.fromTextLine(line)}
// open the SVM model used to predict the type of glass.
val svmModel = getClass.getResource(modelFile).openStream()
val svmModelEvaluator = Predictable.buildEvaluator(svmModel)
val predictedType: TypedPipe[(Int, GlassType.PredictType)] = data
// turn the Glass object into a GlassType
resolvers ++= Seq(
"Conjars" at "http://conjars.org/repo"
)
libraryDependencies ++= Seq(
"org.jpmml" % "pmml-evaluator" % "1.0.21",
"org.jpmml" % "pmml-model" % "1.0.21"
)
import com.twitter.scalding._
import TDsl._
class MapTest(args: Args) extends Job(args) {
val data = TypedTsv[(Int, Int, String, String)](args("input"))
.map{ case (a, b, c, d) =>
val e = if (a > b) c else d
(a, b, c, d, e)
}
.write(TypedTsv[(Int, Int, String, String, String)](args("output")))
import com.twitter.scalding._
import scala.collection.mutable.ListBuffer
import TDsl._
/*
INPUT:
a 1
a 2
a 3
b 1
class NBTestJob(args: Args) extends Job(args) {
val output = args("output")
val iris = Tsv("iris.tsv", ('id, 'class, 'sepalLength, 'sepalWidth, 'petalLength, 'petalWidth))
.read
// The model expects data in "melted" form.
// One Field for the variable names, one for the coresponding values.
val irisMelted = iris
import numpy as np
from pylab import *
import scipy.signal as signal
fs = 1 # 1 day sampling freq
filt = np.ones(7) / 7
w, resp = signal.freqz(filt)