Giter VIP home page Giter VIP logo

getting-cleaningdata's Introduction

Getting and Cleaning Data Project

How the script works

Read the activity labels and features

The first step in the script reads the activity_labels and the features text files to use them later for labeling the Activity column with the value associated, the features file will be used for naming the columns of the merged set

  • aLabels <- read.table("activity_labels.txt")
  • fLabels <- read.table("features.txt")

##Read Data The next section of the script reads the test and train data and binds them in one set:

  • x <- rbind(read.table("./test/x_test.txt"),read.table("./train/x_train.txt"))

With the set already merged, the column names are set using the colnames that were read from features.txt on step 1

  • colnames(x) <- fLabels$V2

Subset only the columns mean and std using grepl

  • stat<-x[,grepl("mean[:(:]", colnames(x)) | grepl("std[:(:]", colnames(x))]

Reading and binding the sets corresponding to activities and subjects

Read Activity Data

  • y <- rbind(read.table("./test/y_test.txt"),read.table("./train/y_train.txt"))

Set Labels instead of values using activity_labels.txt

  • y$V1 = factor(y$V1,labels=aLabels$V2)
  • colnames(y)<-c("Activity")

Read Subject Data

  • s <- rbind(read.table("./test/subject_test.txt"), read.table("./train/subject_train.txt"))
  • colnames(s)<-c("Subject")

###Bind Columns Subject - Activity - Data and generate the Tidy set

  • dat <- cbind(s,y,stat)

Get the average for the data set

  • tidy <- aggregate(dat[, -(1:2)], list(Subject=dat$Subject,Activity=dat$Activity), mean)

Write the tidy data set

  • write.table(tidy, 'tidy.txt', row.name=FALSE)

#CodeBook

I refer you to the README and features.txt files in the original dataset to learn more about the feature selection for this dataset. And there you will find the follow description:

The features selected for this database come from the accelerometer and gyroscope 3-axial raw signals tAcc-XYZ and tGyro-XYZ. These time domain signals (prefix 't' to denote time) were captured at a constant rate of 50 Hz. Then they were filtered using a median filter and a 3rd order low pass Butterworth filter with a corner frequency of 20 Hz to remove noise. Similarly, the acceleration signal was then separated into body and gravity acceleration signals (tBodyAcc-XYZ and tGravityAcc-XYZ) using another low pass Butterworth filter with a corner frequency of 0.3 Hz.

Subsequently, the body linear acceleration and angular velocity were derived in time to obtain Jerk signals (tBodyAccJerk-XYZ and tBodyGyroJerk-XYZ). Also the magnitude of these three-dimensional signals were calculated using the Euclidean norm (tBodyAccMag, tGravityAccMag, tBodyAccJerkMag, tBodyGyroMag, tBodyGyroJerkMag).

Finally a Fast Fourier Transform (FFT) was applied to some of these signals producing fBodyAcc-XYZ, fBodyAccJerk-XYZ, fBodyGyro-XYZ, fBodyAccJerkMag, fBodyGyroMag, fBodyGyroJerkMag. (Note the 'f' to indicate frequency domain signals). I included all variables having to do with mean or standard deviation.

The first columns correspond to the Subject and Activity

  • Subject
  • Activity

For this derived dataset, these signals were used to estimate variables of the feature vector for each pattern:
'-XYZ' is used to denote 3-axial signals in the X, Y and Z directions.

  • tBodyAcc-XYZ
  • tGravityAcc-XYZ
  • tBodyAccJerk-XYZ
  • tBodyGyro-XYZ
  • tBodyGyroJerk-XYZ
  • tBodyAccMag
  • tGravityAccMag
  • tBodyAccJerkMag
  • tBodyGyroMag
  • tBodyGyroJerkMag
  • fBodyAcc-XYZ
  • fBodyAccJerk-XYZ
  • fBodyGyro-XYZ
  • fBodyAccMag
  • fBodyAccJerkMag
  • fBodyGyroMag
  • fBodyGyroJerkMag

The set of variables that were kept for this assignment are:

  • mean(): Mean value
  • std(): Standard deviation

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.