Machine Learning Notes

2013 Sang Han

A collection of notes and useful articles on numerical algorithms.



Markov Chains: A special type of stochastic process. The standard definition of a stochastic process is an ordered collection of random variables:

Self-Organized Criticality (SOC): “Self-Organized” means that from any initial condition, the system tends to move toward a critical state, and stay there, without external control. A system is “critical” if it is in transition between two phases.

Kernel Density Estimation: Because fuck histograms.


  • Least Squares
  • Ridge Regression
  • Last Angle Regression
  • Elastic Net
  • Kernel Ridge Regression
  • Support Vector Machines (SVR)
  • Partial Least Squares (PLS ...
Read More....

Useful Python Tricks

Originally inspired from this blog post. But many have been customized and rewritten into an IPython Notebook.

Note: Written for Python 3


a, b, c = 1, 2, 3

a, b, c

(1, 2, 3)
a, b, c = [1, 2, 3]

a, b, c
(1, 2, 3)
a, b, c = (2 * i + 1 for i in range(3))
a, b, c
(1, 3, 5)
a, (b, c), d = [1, (2, 3), 4]

a, b, c, d
(1, 2, 3, 4)

Iterating over list index and value pairs (enumerate)

a = ['Hello', 'world', '!']

for i, x in enumerate(a):
    print('{}: {}'.format(i ...
Read More....

Prime Sieves and Python Data Structures

Recently, I’ve been working through Project Euler in order to improve my core programming skills.

One of those recurring problems requires efficiently calculating and testing for prime numbers. The first algorithm that comes to mind is The Sieve of Eratosthenes. The Sieve, is one of many prime sieves, and is a simple yet time efficient algorithm for finding all the primes below a certain limit.

The Algorithm

  1. Make a table one entry for every number \(2 \leq n \leq limit\)
  2. Starting at 2, cross out all multiples of 2, not counting 2 itself.
  3. Move up to the next number ...
Read More....

Swift Program is Swift, Except When it’s Not


This past WWDC Apple revealed a brand new programming language called Swift to the masses and passed it out to Apple Developers packaged in the XCode 6 Beta.

Language Features

  • Type Inferencing and Automatic Reference Counting (ARC)
  • Optional Bindings and Generic Functions
  • Integration with Objective-C
  • First-Class Functions and Closures

My initial impressions were pretty high. However, after some quick benchmarking examples, those feelings later matured to an understanding of it’s "beta" characteristics. Many of the underlying optimization still have some kinks to work through.

And by kinks, I mean some big fixes


Here are a couple examples of ...
Read More....

Pelican: A Blogging Engine Written in Python

There are many static site generators out there.

The most famous and well known being, Jekyll and Octopress.

Jekyll is used by Github Pages as the default generator, while Octopress is a framework for Jekyll geared specifically for blogging. However, the reason why I decided to use Pelican over both, is because Pelican is written in Python, and therefore support the reStructuredText markup by default and is a language I feel comfortable in case I need to get down and fix the engine. One of my primary forcuses of blogging is so that I can also use it as a ...

Read More....

Swift: Bubble Sort

// Sang Han
// An implementation of a bubble party/bubble sort written in swift

import Foundation

func exchange<T>(inout a: T, inout b: T)
    let tmp = a
    a = b
    b = tmp

func bubbleSort(inout array: [Int]) -> [Int]
    let length = array.count

    var count, pos: Int
    for (count=0; count<length-1; count++)
        for (pos=0; pos<(length-count-1); pos++)
            if (array[pos] > array[pos+1]) {
                exchange(&array[pos], &array[pos+1])
    return array

func sortMain(arrayLength: Int) -> [Int]
    var array: [Int] = []
    for _ in 0..<arrayLength {
    return bubbleSort(&array)
Read More....