Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
> library(MASS) # load the MASS package
> height.response = na.omit(survey$Height)
> n = length(height.response)
> s = sd(height.response) # sample standard deviation
> SE = s/sqrt(n); SE # standard error estimate
[1] 0.6811677
>
> print(paste("Standard Error:", SE))
[1] "Standard Error: 0.68116773214787"
>
> system.time({ caret.model <- train(carat ~ depth + table + price + x + y + z, data=diamonds, distribution="gaussian", method="gbm", trControl = trainControl(method="none", number=1), tuneLength=1, verbose=FALSE)})
user system elapsed
1.108 0.060 1.188
> system.time({ model <- gbm(carat ~ depth + table + price + x + y + z, data=diamonds, distribution="gaussian")})
user system elapsed
0.818 0.026 0.856
print("start.207")
for (i in 1:5) {
t <- get(paste0("d", i));
y <- factor(t[,c("start.207")], levels=c("1", "0"))
x <- t[,c("stop.165","stop.166","stop.167","stop.168","stop.169","stop.185",
"stop.186","stop.187","stop.188","stop.189","stop.205","stop.206",
"stop.207","stop.208","stop.209","stop.225","stop.226","stop.227",
"stop.228","stop.229","stop.245","stop.246","stop.247","stop.248","stop.249")]
md <- train(x, y, method="rf", ntree=ntrees, trControl=trainControl(method="cv"))
> install.packages("dplyr")
also installing the dependency ‘DBI’
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.3/DBI_0.5-1.tgz'
Content type 'application/x-gzip' length 353669 bytes (345 KB)
==================================================
downloaded 345 KB
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.3/dplyr_0.5.0.tgz'
Content type 'application/x-gzip' length 4841443 bytes (4.6 MB)
@earino
earino / foo
Created October 21, 2016 14:38
> class(hash_table)
[1] "hash"
attr(,"package")
[1] "hash"
> str(hash_table)
Formal class 'hash' [package "hash"] with 1 slot
..@ .xData:<environment: 0x24f72ec8>
> object_size(hash_table)
type: 17
Error: Unimplemented type
@earino
earino / evil_library.R
Created August 23, 2016 18:59
Replace the library() function so it logs
if (! "old_library" %in% ls()) {
old_library <- library
}
logging_library <- function(...) {
cat(as.character(substitute(...)),
sep="\n",
file="library_log.txt",
append=TRUE)
@earino
earino / constant.pl
Created February 27, 2013 21:40
This is why 'use constant' is bad.
#!/usr/bin/env perl
#
use warnings;
use strict;
use Data::Dumper;
use constant MY_CONSTANT => 13;
my %foo = (MY_CONSTANT => 'dingle');
@earino
earino / script.js
Created November 23, 2012 22:42
Poor Man's Nagios
/**
* This function fetches a url and gets some of the instrumentation data.
*
* @param url the Url to fetch and instrument
* @return an object which contains the status code, latency, and contentLength.
*/
function fetchUrl(url) {
try {
var start = new Date().getTime();
var resp = UrlFetchApp.fetch(url);
#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;
my @records = ();
my $now = time();
my $weeks = 604800 * 52;