# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages
# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats
# For example, here's several helpful packages to load in 

library(ggplot2) # Data visualization
library(readr) # CSV file I/O, e.g. the read_csv function

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

#system("ls ../input")

# Any results you write to the current directory are saved as output.
#setwd("../input")
train_data = read_csv("../input/train.csv")

train_data[1:5,]

k = length(unique(train_data$place_id))

# First, we should look at how accuracy effects x and y.  We can use regression for this.
## For now, we will just find the relationship between location and accuracy for a single place.
place1_data = train_data[train_data$place_id == 8523065625,]
place1_data$xdist = abs(place1_data$x - mean(place1_data$x))
place1_data$ydist = abs(place1_data$y - mean(place1_data$y))
xacc_fit = lm(xdist~accuracy, data=place1_data)
yacc_fit = lm(ydist~accuracy, data=place1_data)

summary(xacc_fit)
summary(yacc_fit)

plot(place1_data$accuracy, place1_data$xdist)
plot(place1_data$accuracy, place1_data$ydist)


#print(kmeans(train_data[-1,],k))





