Skip to content

Instantly share code, notes, and snippets.

View davidrichards's full-sized avatar

David Richards davidrichards

View GitHub Profile
require 'rubygems'
require 'mlp'
require 'data_frame'
IRIS = {1 => 'Iris Setosa', 2 => 'Iris Versicolour', 3 => 'Iris Virginica'}.freeze
KEYS = {'Iris-setosa' => 1, 'Iris-versicolor' => 2, 'Iris-virginica' => 3}.freeze
@mlp = MLP.new(:hidden_layers => [4], :output_nodes => 3, :inputs => 4)
@df = DataFrame.new(:sepal_length, :sepal_width, :petal_length, :petal_width, :class)
# This is used when the data set's true max and min can't be calculated.
# It provides approximate values for normalization.
class PseudoNormalize
require 'mathn'
class << self
def process(opts={})
sample = opts.delete(:sample)
opts = {:sample => sample} if opts.empty
pn = new(opts)
pn.process(*sample)
data_frame (master): plain_frame
Loading Data Frame version: 0.1.8
>> df = DataFrame.from_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/forest-fires/forestfires.csv')
=> DataFrame rows: 517 labels: [:x, :y, :month, :day, :ffmc, :dmc, :dc, :isi, :temp, :rh, :wind, :rain, :area]
>> df.month.categories
=> ["apr", "aug", "dec", "feb", "jan", "jul", "jun", "mar", "may", "nov", "oct", "sep"]
>> df.wind.categories
=> [0.4, 0.9, 1.3, 1.8, 2.2, 2.7, 3.1, 3.6, 4, 4.5, 4.9, 5.4, 5.8, 6.3, 6.7, 7.2, 7.6, 8, 8.5, 8.9, 9.4]
>> df.wind.add_category(0) {|e| e <= 5}
=> {0=>#<Proc:0x0259cdf4@(irb):4>}
@davidrichards
davidrichards / buddy_ebsen.rb
Created December 24, 2010 14:42
The main application file
# ============================
# = Load Server Dependencies =
# ============================
require 'rack-flash'
require 'warden'
require 'sinatra'
require 'haml'
require 'sinatra_more/markup_plugin'
# ===============================
@davidrichards
davidrichards / binary.rb
Created May 12, 2011 07:50
Specificity and Sensitivity: some play-around code I used to understand these two terms.
module Confusion
module MatrixBehavior
# A matrix of the values (actual: rows, predicted: columns)
attr_reader :values
protected
def assert_matrix_behavior(opts)
assert_values(opts)
end
@davidrichards
davidrichards / tpl-basicapp.rb
Created May 25, 2011 18:20 — forked from paulmars/template.rb
Rails 3, RSpec, Factory_Girl, HAML, SASS, Devise, JQuery, Backbone.js, jammit, haml.js
## Rails App Template
## Useful for Rails 3.0.x and Ruby 1.9.2
## Run using $ rails new [appname] -JT -m tpl-basicapp.rb
# ========
# = Gems =
# ========
# pre-install spork, dydram and elastic_searchable
run "gem install spork -v 0.9.0.rc --pre"
@davidrichards
davidrichards / Gemfile
Created September 9, 2011 20:52
Takeaways from Jasmine Class
group :development, :test do
gem "growl_notify"
gem "guard-jasmine-headless-webkit"
# Can bring this back in when we're ready to go with 3.1
# gem "jasmine-rails"
gem "jasmine-headless-webkit"
gem "rb-fsevent"
gem "guard-jammit", :git => "git://github.com/johnbintz/guard-jammit.git"
end
@davidrichards
davidrichards / hash.rb
Created November 10, 2011 08:33
Recursive symbolize keys
require 'active_support/core_ext'
class Hash
def recursive_symbolize_keys!
symbolize_keys!
values.each do |h|
case h
when Array
h.each{|vv| vv.recursive_symbolize_keys! if Hash === vv }
gem 'jquery-rails'
gem 'coffee-rails', '~> 3.1.1'
gem "haml-rails"
gem 'ruby-haml-js'
@davidrichards
davidrichards / learning_curve.rb
Created November 27, 2011 12:01
The Learning Curve
=begin
One of my favorite equations from business school: the learning curve.
Human experience has shown that every time our experience with a single
task doubles, our efficiency increases by 20%. Our learning curve is
actually around 20%, with a 95% confidence rate around 10% and 30%.
This was the equation that founded BCG as they measured everything
related to the then-new aviation industry. It's been used to measure
all sorts of human tasks and has proven pretty resilient for people of
all kinds of backgrounds and aptitudes.