Skip to content

Instantly share code, notes, and snippets.

@gcardone
gcardone / ConfidenceIntervalApp.java
Last active March 31, 2024 13:13
How to calculate confidence interval for means with unknown standard deviation using the Student t distribution. Needs Apache Commons Math library.
import org.apache.commons.math3.distribution.TDistribution;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
public class ConfidenceIntervalApp {
public static void main(String args[]) {
// data we want to evaluate: average height of 30 one year old male and female toddlers
// interestingly, at this age height is not bimodal yet
double data[] = new double[] { 63.5, 81.3, 88.9, 63.5, 76.2, 67.3, 66.0, 64.8, 74.9, 81.3, 76.2, 72.4, 76.2, 81.3, 71.1, 80.0, 73.7, 74.9, 76.2, 86.4, 73.7, 81.3, 68.6, 71.1, 83.8, 71.1, 68.6, 81.3, 73.7, 74.9 };
@gcardone
gcardone / gist:6757817
Created September 30, 2013 00:23
How to shuffle an array using the Fisher-Yates shuffle (also known as the Knuth shuffle: The Art of Computer Programming volume 2: Seminumerical algorithms, Algorithm P).
#include <algorithm>
#include <cstdlib>
#include <iterator>
#include <iostream>
#ifndef N
#define N 100
#endif
inline int rand_range(int min, int max) {
@gcardone
gcardone / ConfidenceInterval.py
Created August 10, 2014 17:58
How to calculate confidence interval for means with unknown standard deviation using the Student t distribution. Needs numpy and scipy
#!/usr/bin/env python
from scipy.stats import t
from numpy import average, std
from math import sqrt
if __name__ == '__main__':
# data we want to evaluate: average height of 30 one year old male and
# female toddlers. Interestingly, at this age height is not bimodal yet
data = [63.5, 81.3, 88.9, 63.5, 76.2, 67.3, 66.0, 64.8, 74.9, 81.3, 76.2,
@gcardone
gcardone / color_histogram_svm.py
Created August 13, 2014 09:58
A simple binary image classifier based on scikit-learn. It uses (binned) RGB color space as feature vector.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Images binary classifier based on scikit-learn SVM classifier.
It uses the RGB color space as feature vector.
'''
from __future__ import division
from __future__ import print_function
from PIL import Image
from sklearn import cross_validation