Giter VIP home page Giter VIP logo

gacdcourseproject's Introduction

GACDCourseProject

This is the course project for the Getting and Cleaning Data Course

The R script run_analysis.R cleans the Samsung smartphone dataset. A full description of the data used in this project can be found at The UCI Machine Learning Repository

The source data for this project can be found here.

###Instructions for use:

Step 1: Create a working directory for this project say "my_project_folder".

Step 2: Download and extract the zip file mentioned above in this folder.

Step 3: Download the run_analysis.R file in my_project_folder.

The heirarchy at this point should be :

  • my_project_folder/
  • UCI HAR Dataset/
  • run_analysis.R

The run_analysis.R script has a function named analyze which has the parameter path

  • @path - The path of the current working directory i.e. "/home/.../my_project_folder/"

Step 4: Open R and set the current working directory using setwd

Step 5: Source the R script using source("run_analysis.R")

Step 6: Type tData <- analyze("/home/.../my_project_folder/")

You will get the resulting tidy data as "tData"


###Internal working of run_analysis.R:

####Merge step Once you have called analyze(path) in the manner shown above;

The script will pick up the training files and the test files in the .txt format into data frames using the read.table method as shown in the code.

First, it merges the training and test files corresponding to features

Then, it merges the training and test files corresponding to Subject

Then, it merges the training and test files corresponding to Activity(i.e. y_train and y_test)

Then, it merges the three data frames got as a result of the above 3 steps into one data frame called "data".

####Giving variable names to all columns

This step uses the "features.txt" file to make a mapping between feature number and variable name.

The column names extracted from the map and the new column names "Subject" and "Activity" are assigned to "data"

####Extracting only the measurements on the mean and standard deviation for each measurement This step involves searching the column names assigned before, for mean() and std(), with the exceptions of Subject and Activity and selecting only these in the resulting frame.

####Using descriptive activity names to name the activities in the data set As in the case of feature variable extraction, a map(a simple data frame in this case) is created between activity number and label from the file "activity_labels.txt"

Then, the "Activity" column of the "data" data frame is traversed and each Activity code is replaced by its corresponding label(not directly but by making a character vector "activityLabel" and replacing the entire column afterwards)

####creating an independent tidy data set with the average of each variable for each activity and each subject. This step uses the melt function of the reshape2 package and later on dcast to find the averages using the code shown in the script.

The resulting tidy data set is returned from the analyze function.

It can be further written to a text file using write.table(tidyData,file="tidyData.txt",row.name = FALSE) by the user.

gacdcourseproject's People

Contributors

saini5 avatar

Watchers

James Cloos 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.