This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cars | |
plot(cars) | |
cars.lm = lm(dist~.,cars) | |
summary(cars.lm) | |
# dist = 3.03*speed - 17.58 | |
plot(cars) | |
abline(cars.lm, col="red") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
import numpy as np | |
from sklearn import linear_model | |
from matplotlib import pyplot as plt | |
from matplotlib import lines | |
data = np.loadtxt("../data/cars.csv", delimiter=",", skiprows=1, usecols=(1, 2)) | |
dest = data[:, 0] | |
speed = data[:, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "hello world" | |
list = [] | |
list.append(1) | |
list.append(2) | |
list.append(3) | |
for n in list: | |
print "%d" %n | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pulp | |
problem = pulp.LpProblem('hamburg and omelet', pulp.LpMaximize) | |
# create variables | |
x = pulp.LpVariable('x', cat = 'Integer') | |
y = pulp.LpVariable('y', cat = 'Integer') | |
# maximize | |
problem += 400 * x + 300 * y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
import FuncDesigner as fd | |
from openopt import LP | |
""" | |
max. 400x + 300y | |
sub. 60x+40y <= 3800 | |
20x+30y <= 2100 | |
20x+10y <= 1200 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertion_sort(target): | |
for i in range(len(target)): | |
insert(target, i, target[i]) | |
def insert(target, pos, value): | |
i = pos - 1 | |
while (i >= 0 and target[i] > value): | |
target[i + 1] = target[i] | |
i = i - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
from benchmarker import Benchmarker | |
import random | |
import sort | |
def initdata(): | |
data = range(100) | |
random.shuffle(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort(target): | |
median_sort(target, 0, len(target) - 1) | |
return target | |
def median_sort(target, left, right): | |
if left < right: | |
# find median | |
mid_point = (left + right) / 2 | |
min_value = target[left] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quick_sort(target): | |
if len(target) <= 1: | |
return target | |
pivot = target[0] | |
left = [] | |
right = [] | |
for x in xrange(1, len(target)): | |
if target[x] <= pivot: | |
left.append(target[x]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def select_sort(target): | |
p = len(target) | |
for i in xrange(p - 1): | |
min = target[i] | |
t = i | |
for j in xrange(i + 1, p): | |
if target[j] < min: | |
min = target[j] | |
t = j | |
target[t] = target[i] |
OlderNewer