Skip to content

Instantly share code, notes, and snippets.

def bias_replace_missing_with_avg(data_set):
'''
For some reason, this is my longest function.
It's all the partitioning and partition undoing.
Replace 'None' values (missing values) with the average of all existing
values for that attribute.
'''
notNone = lambda x: x is not None
def mean(lst):
'''
Calculate the mean of the input list.
'''
l = len(lst)
return float(sum(lst)) / l if l > 0 else None
def list_mode(lst):
return max(lst, key=lst.count)
def classify(self, instance):
'''
given a single observation, will return the output of the tree
'''
attr = self.decision_attribute
if self.label is not None:
return self.label
elif self.splitting_value:
import math
from node import Node
from collections import Counter
#import sys
import timeit
iterations = 0
notNone = lambda x: x is not None
def recursive_size(s, nodes):
'''
tail recursive size
'''
num = len(nodes)
if (num == 0): return s
children = n.children.values()
return sum([ recursive_size(s + num, children) for n in nodes ])
<link2>
<a each={ items } class="btn btn-success" role="button" onclick={ goto( itemname ) }>
Get Buyer Link
</a>
<script>
this.items = [{
itemname:"LEI",
itemtag: "lei",

Botloader Spec

An example

// app.js
var botloader = require('botloader')

botloader.with({
  slack: new Slack(<Bot Access Key>),
  octopus: require('./botconfig')
function helloWorldWithOptions (toWhom, { postfix1: p1, postfix2: p2='' }, greeting='Hello', additionalOptions={}) {
let { pre: preFn=String } = additionalOptions
return preFn(`${greeting}, ${toWhom}${p1}${p2}`)
}
helloWorldWithOptions('world', { postfix1: '!' }) // => 'Hello, world!'
helloWorldWithOptions('world', { postfix1: '!', postfix2: '1' }) // => 'Hello, world!1'
helloWorldWithOptions('Mom', { postfix1: '?' }, undefined, additionalOptions={ pre: (str) => str.toUpperCase() })
// => 'HELLO, MOM?'
"my god it's full of stars"
{ (25000, 2000, 0, 0): { 'east': [(25500, 2000, 0, 1)],
'northeast': [(25250, 2750, 1, 0)],
'northwest': [],
'southeast': [],
'southwest': [],
'west': []},
(25000, 3500, 2, 0): { 'east': [(25500, 3500, 2, 1)],
'northeast': [(25250, 4250, 3, 0)],
'northwest': [],
import pprint
import math
pp = pprint.PrettyPrinter(indent=2, width=120)
pp.pprint("my god it's full of stars")
def turbine_layout(rows, cols, startx=25000, starty=2000, rowgap=500, colgap=750, skewx=lambda _: 0):
turbines = []