{"cells":[{"metadata":{"_uuid":"527dcc0d6decadd3d89027b104aaf893ce16fe7c","_execution_state":"idle","trusted":true},"cell_type":"code","source":"## Importing packages\n\n# This R environment comes with all of CRAN and many other helpful packages preinstalled.\n# You can see which packages are installed by checking out the kaggle/rstats docker image: \n# https://github.com/kaggle/docker-rstats\n\nlibrary(tidyverse) # metapackage with lots of helpful functions\n\n## Running code\n\n# In a notebook, you can run a single code cell by clicking in the cell and then hitting \n# the blue arrow to the left, or by clicking in the cell and pressing Shift+Enter. In a script, \n# you can run code by highlighting the code you want to run and then clicking the blue arrow\n# at the bottom of this window.\n\n## Reading in files\n\n# You can access files from datasets you've added to this kernel in the \"../input/\" directory.\n# You can see the files added to this kernel by running the code below. \n\nlist.files(path = \"../input\")\n\n## Saving data\n\n# If you save any files or images, these will be put in the \"output\" directory. You \n# can see the output directory by committing and running your kernel (using the \n# Commit & Run button) and then checking out the compiled version of your kernel.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"45d79b3448fcfc95550231cae0b48d2402e9d4bd"},"cell_type":"markdown","source":"Gonna attempt to just make the most basic of basic models.  Will use the test set as testing (bad practice)."},{"metadata":{"trusted":true,"_uuid":"d5b28e38f4523100face3acfb380a6cfd6a3b7e6"},"cell_type":"code","source":"#testdata <- read.csv(\"../input/test.csv\")\n\n\n\n#head(testdata)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"511a4472f116211aad892be162bb51f4d2c78080"},"cell_type":"code","source":"traindata <- read.csv(\"../input/preprocessedtrain/preProcessedTrain.csv\")\noldata <- read.csv(\"../input/digit-recognizer/train.csv\")\nhead(traindata)\ntestdata <- read.csv(\"../input/preprocessedtest/preProcessedTest.csv\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"library(class)\nnormalize <- function(x) {\n    return ((x - min(x)) / (max(x) - min(x)))\n}\ntraindatanorm <- as.data.frame(lapply(traindata, normalize))\ntestdatanorm <- as.data.frame(lapply(testdata, normalize))\ntrain <- traindatanorm\ntest<- testdatanorm\ntrainlabels <- oldata$label\n\n\npredictions <- knn(train, test, cl = trainlabels, k = 21)\nhead(predictions)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"head(predictions, 500)\nlength(predictions)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a8b87b2dba2e85d3b4cf974232ef2ecf852c667e"},"cell_type":"code","source":"results <- predictions\nresultsdf <- data.frame('ImageId'= c(1:28000), 'Label'=results)\nresultsdf","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"091de3acecc95e347287c89d0411a563bc3b1518"},"cell_type":"code","source":"write.csv(resultsdf, 'submission.csv', row.names=F)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Traindata2 (brandon variables) got 73.05 acc\nTraindata3 (eric variables) got 60.40 acc\nLet's combine!  Got 0.83 accuracy.  Now going to try other models.\nKNN got 0.96 accuracy with just Brandon variables lul\n"}],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"3.4.2","file_extension":".r","codemirror_mode":"r"}},"nbformat":4,"nbformat_minor":1}