Last active
January 29, 2016 21:23
-
-
Save jameskyle/7605a0c61db8144af396 to your computer and use it in GitHub Desktop.
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
# 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