Skip to content

Instantly share code, notes, and snippets.

View ottadini's full-sized avatar
👴

ben harrison ottadini

👴
View GitHub Profile
@ottadini
ottadini / lm_eqn.R
Last active July 11, 2017 03:41
Annotate a ggplot2 plot with regression line equation and R^2
# Source: http://stackoverflow.com/q/7549694/857416
lm_eqn = function(m) {
# Displays regression line equation and R^2 value on plot
# Usage:
# p + annotate("text", x=25, y=300, label=lm_eqn(lm(y ~ x, df)), parse=TRUE)
l <- list(a = format(coef(m)[1], digits = 2),
b = format(abs(coef(m)[2]), digits = 2),
r2 = format(summary(m)$r.squared, digits = 3));
@ottadini
ottadini / som-prediction.R
Last active December 20, 2015 04:19
An attempt at prediction of TC using the kohonen package.
# ===== #
library(kohonen)
# Load data, available at https://gist.github.com/ottadini/6068259
somdata <- read.csv("somdata.csv")
# Create SCALED test and training sets from data:
inTrain <- sample(nrow(somdata), nrow(somdata)*(2/3))
training <- scale(somdata[inTrain, ])
@ottadini
ottadini / somdata.csv
Last active December 20, 2015 04:08
Data file (CSV) for supervised mapping and prediction using kohonen package. "MEAS_TC","SP","LN","SN","GR","NEUT"
MEAS_TC SP LN SN GR NEUT
2.78 59.1810903609045 33.7436448559876 19.7536103778765 66.5766474766635 257.0368012729
1.49 49.0477497329406 184.145977437229 139.079797489143 54.7505195826885 326.800134003894
1.49 49.1289016073479 183.588534123696 138.027677512105 55.5411398043229 327.473945839365
2.201275709 18.2403310337942 19.2038626516248 10.7474792741976 62.0449186292617 494.416136250187
2.201275709 18.2155224379773 19.1800937852543 10.7244616233215 61.8744774871462 494.740941830979
1.276476312 9.33776939549743 14.1606094244497 19.0690215694105 14.9961159237259 363.002021309839
1.276476312 9.30627807118255 14.1655436529726 19.0953021764089 15.0205158738082 363.592835920731
2.4162441005 65.9385510407827 11.5964588279339 13.1929031148605 43.785062332152 142.583172944641
2.4162441005 66.2962310687366 11.5462659711476 13.1725547197125 43.607290645435 142.672765831378