library(readr) # CSV file I/O, e.g. the read_csv function
library(data.table) #reading in the data
library(dplyr) #dataframe manipulation
library(ggplot2) #viz
library(ranger) #the random forest implementation
library(plotly) #3D plotting
library(tidyr) #dataframe manipulation
library(FNN) #k nearest neighbors algorithm
library(xgboost)

fb <- fread("../input/train.csv", integer64 = "character", showProgress = FALSE)
fb$place_id <- as.factor(fb$place_id)
ids <- count(fb,fb$place_id)
ids <- ids[n>=500]

fb$hour = (fb$time/60) %% 24
fb$weekday = (fb$time/(60*24)) %% 7
fb$month = (fb$time/(60*24*30)) %% 12 #month-ish
fb$year = fb$time/(60*24*365)
fb$day = fb$time/(60*24) %% 365

fb <- fb[fb$place_id %in% ids$place_id,]

model_rf <- ranger(place_id ~ x + y + accuracy + hour + weekday + month + year,
                   fb,
                   num.trees = 100,
                   write.forest = TRUE,
                   importance = "impurity")

pred = predict(model_rf, small_val)
