Skip to content

Instantly share code, notes, and snippets.

@jameskyle
Last active January 29, 2016 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameskyle/7605a0c61db8144af396 to your computer and use it in GitHub Desktop.
Save jameskyle/7605a0c61db8144af396 to your computer and use it in GitHub Desktop.
# Create some data
x <- seq(0, 10, by=0.01)
y <- exp(1)^-x
df <- data.frame(x=x, y=y)
# Add some noise.
df$y <- jitter(df$y, amount=.1)
print("Plotting original data...")
plot(df)
print("Press [enter] to continue")
line <- readline()
print("Training model based on log(y) ~ x.")
model <- lm(log(y) ~ x)
print(summary(model))
plot(model)
print("Press [enter] to continue")
line <- readline()
print("Predictions...")
df$pred <- predict(model, list(df$x))
plot(df$y)
lines(exp(df$pred),col="red",lwd=2)
print("Press [enter] to continue")
line <- readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment