Skip to content

Instantly share code, notes, and snippets.

@JoshAshby
Created April 27, 2011 20:04
Show Gist options
  • Save JoshAshby/945058 to your computer and use it in GitHub Desktop.
Save JoshAshby/945058 to your computer and use it in GitHub Desktop.
Random bit of R as part of a basic linear machine learning (ish) project for House-Inventory
library(ggplot2)
data = read.csv("/home/joshua/Downloads/test_data.csv", header = TRUE)
plot = ggplot(mydata, aes(x, y)) + geom_point() + ylab('Quantity') + xlab('Days')
m = length(data$x)
theta = matrix(c(0,0), nrow=1)
x = matrix(c(rep(1,m), data$x), ncol=2)
y = matrix(data$y, ncol=1)
theta = solve(t(x) %*% x) %*% (t(x) %*% y)
plot + geom_abline(intercept=theta[1], slope=theta[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment