Code Monkey home page Code Monkey logo

getdata-project's Introduction

Tidy and Average UCI Human Activity Recognition (HAR) Using Smartphones Data Set

Installation

The following R package dependencies need to be installed:

  • plyr
  • reshape2
  • data.table

The script has been tested using R version 3.2.2 on Mac OS X Yosemite 10.5.5.

Invocation, Input and Output

The script must be run from the project root directory. For example with:

cd /work/getdata-project
Rscript run_analysis.R

The script will download and unzip the original UCI HAR data to the UCI HAR Dataset directory, unless that directory already exists (to save time and bandwidth on subsequent runs).

It writes four new dataset text files to disk using write.table. The primary output file is saved in the working directory:

  • averages_by_activity_and_subject.txt

The remaining three are saved for reference under a tidy directory:

  • subjects.txt
  • activities.txt
  • HAR_sensor_measurements.txt

The above are all described in more detail in the Code Book

run_analysis.R steps

The script performs the following steps.

  • Download and unzip the UCI HAR dataset unless the directory already exists
  • Read in the dataset using read.table and data.table's fread (on large tables for speed and to support later operations like join and setcolorder)
  • Set column names on activities, subjects and observations using colnames. Observation columns are for the time being named from the original features.txt.
  • Change activity labels to lower-case and merge them into the test and train data sets.
  • Merge activity names and subject ids into the test and train data sets using cbind
  • Merge the test and train datasets using rbind, also adding a new variable on subject for sample type (test vs. train).
  • Select the mean and standard deviation columns, with a combination of grep and subset.
  • Change the measurement columns to more descriptive labels, as described in the Code Book. This is done by iterating over a list of pattern => replacement pairs and using gsub. Then data.table package's setcolnames function is used (for speed and readability).
  • Average each variable for each activity and each subject. reshape2 package's melt and dcast functions perform the mean calculations and reshape the data frame into 88 variables with 187 records.
  • In the tidied HAR sensor measurement data, move fixed variable (activity name and subject) columns to the beginning (columns 1 and 2).
  • Write the datasets using write.table with row.names = FALSE

References

Davide Anguita, Alessandro Ghio, Luca Oneto, Xavier Parra and Jorge L. Reyes-Ortiz. A Public Domain Dataset for Human Activity Recognition Using Smartphones. 21th European Symposium on Artificial Neural Networks, Computational Intelligence and Machine Learning, ESANN 2013. Bruges, Belgium 24-26 April 2013.

getdata-project's People

Contributors

emurphy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.