Skip to content

Instantly share code, notes, and snippets.

@philippstroehle
philippstroehle / Chetan auto.arima
Created August 19, 2013 07:03
#R #arima #forecast
require(forecast)
resultsAR = NULL
resultsMA = NULL
# start a loop here and feed it new data
tmp = data$Value
tmp = tmp[1:100]
library(ggplot2)
library(gridExtra)
mtcars$cyl <- ordered(mtcars$cyl)
p <- ggplot(mtcars, aes(mpg, hp, colour = cyl)) + geom_point()
p1 <- p + theme(legend.position = "none")
p2 <- ggplot(mtcars, aes(x=mpg, group=cyl, colour=cyl))
p2 <- p2 + stat_density(fill = NA, position="dodge")
class Foo(object):
pass
class Bar(object):
pass
dispatch_dict = {"Foo": Foo, "Bar": Bar}
dispatch_dict["Foo"]() # returns an instance of Foo
>>> import itertools
>>> x = itertools.count(0)
>>> x.__class__.__name__
'count'
@philippstroehle
philippstroehle / Introspection_example.py
Created September 14, 2013 11:23
python introspection
baseClass = self.__class__.__name__
methodToCall = getattr(self,"selectJobs"+baseClass)
#now = self.selectJobsExpectation(J)
now = methodToCall(J)
>>> from pylab import *
>>> plot([1,3,2])
[<matplotlib.lines.Line2D object at 0x102bc8950>]
>>> gca()
<matplotlib.axes.AxesSubplot object at 0x102790cd0>
>>> gca().add_patch(Rectangle((1,1),1,1))
<matplotlib.patches.Rectangle object at 0x102790510>
>>> savefig("rect.png")
@philippstroehle
philippstroehle / profileMemory.py
Created September 16, 2013 20:46
Profiling runtime and memory
@profile # python -m memory_profiler example.py
def my_func():
a = [1] * (10 ** 6)
b = [2] * (2 * 10 ** 7)
del b
return a
if __name__ == '__main__':
my_func()
plot.area<-function(x,col=NULL,horiz=F,prop=T,stp.ln=T,grp.ln=T,axs.cex=1,axs.lab=T,lab.cex=1,
names=c('Group','Step','Value'),...){
#sort out color fector
if(!is.null(col)){
if(sum(col %in% colors()) != length(col)) stop('col vector must be in "colors()"')
col<-colorRampPalette(col)(ncol(x))
}
else col<-colorRampPalette(c('lightblue','green'))(ncol(x))
# do this before importing pylab or pyplot
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt