{"cells":[
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# Load the libraries\nlibrary(ggplot2) # Data visualization\nlibrary(readr) # CSV file I/O, e.g. the read_csv function\nlibrary(relaimpo)\n\nfbdata_full <- read.csv(\"../input/train.csv\")\n\n#check the rows and colms of fbdata_full\ndim(fbdata_full)\n"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# Since the data is large , I have taken 5% sample of the tran.csv data for below Analysis.\n#fbdata <- sample(fbdata_full, nrow(fbdata_full) * 0.05)\nfbdata <- fbdata_full[sample(nrow(fbdata_full)*0.05),]\n\n#check the rows and colms of fbdata\n\ndim(fbdata)\n\n\n"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "#Let's check first 6 rows of the 5% sample to get better understanding of data in file \nhead(fbdata)\n\n\n"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "\n#Let's check the data type , min , max values of each column.\nstr(fbdata)\n\n\n#To Summarize the data\nsummary(fbdata)\n\n"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "\n#Let's focus on x and y columns now.\n#Min value for x and y is 0 and 10 respectively.\n#As we already know that the places are located in 10 X 10 km. Hence we can confirm that units for X and Y are in kilometers.\n\n#Let's focus on accuracy now.\n#Also accuracy has min value as 1 and max value as 1016 from original data. \n#We already know that the places are located in 10 X 10 km. So we can conclude that the accuracy should not be in KM as max value of accuracy (1016) will not fit in 10 X 10 km range.\n \n#So we can assume that the accuracy is in meters. That means less the accuracy value then better will be the prediction.\n\n#Lets check on time column.\n#max value for time is 39997. When convert it to hour from epoch standard time max value of .... will be .... hr. \n\n# Free Memory\nrm(fbdata_full)\n\n# To plot Normal Prob chart for X\nfbdata_lm <- lm(data = fbdata, fbdata$place_id ~ fbdata$x)\nfbdata_stres <- rstandard(fbdata_lm)\nqqnorm(fbdata_stres, xlim=c(-4,4), ylim = c(-2,2), main=\"Normal Distribution for X\")\nqqline(fbdata_stres)\n"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "\n# To plot Normal Prob chart for Y\nfbdata_lm_y <- lm(data = fbdata, fbdata$place_id ~ fbdata$y)\nfbdata_stres_y <- rstandard(fbdata_lm_y)\nqqnorm(fbdata_stres_y, xlim=c(-4,4), ylim = c(-2,2), main=\"Normal Distribution for Y\")\nqqline(fbdata_stres_y)\n\n# Other way to plot Normal Prob chart for Time\nattach(fbdata)\nqqnorm(fbdata$time, main=\"Normal Distribution for Time\")\nqqline(fbdata$time)\n\n# To plot Normal Prob chart for Accuracy\nqqnorm(fbdata$accuracy, main=\"Normal Distribution for Accuracy\")\nqqline(fbdata$accuracy)\n\n# To plot Normal Prob chart for All 4 variables\nqqnorm(fbdata$x+fbdata$y+fbdata$time+fbdata$accuracy, main=\"Normal Distribution for All Data\")\nqqline(fbdata$x+fbdata$y+fbdata$time+fbdata$accuracy)\n\n# All of above graphs are normally distributed across place_ids Except Accuracy. \n# So we can say that even though the data is purposefully created with some vague values, It is still normally distributed and does not need additional cleaning.\n\n# To know the relative importance of all columns for prediction :\nmodel <- lm(data = fbdata, place_id ~ time + x + y + accuracy)\ncalc.relimp(model, type=c(\"lmg\",\"last\",\"first\",\"pratt\"),rela=TRUE)\n\n# Here we are bootstrapping the relative importance model.\n boot_model <- boot.relimp(model, b = 1000, type = c(\"lmg\", \"last\", \"first\", \"pratt\"), rank = TRUE, diff = TRUE, rela = TRUE)\n booteval.relimp(boot_model)\n\n# Looks like the time is the most important attribute to predict the data, then comes accuracy , then Y and last X. Below chart shows the relative importance of all attributes\nplot(booteval.relimp(boot_model),sort=TRUE)\n"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": ""
 }
],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"}}, "nbformat": 4, "nbformat_minor": 0}