-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_Machine_Learning_Course_Project_Submitted.Rmd
More file actions
87 lines (68 loc) · 3.17 KB
/
Practical_Machine_Learning_Course_Project_Submitted.Rmd
File metadata and controls
87 lines (68 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: "Practical_Machine_Learning_Course_Project.Rmd"
output:
html_notebook: default
html_document: default
---
Prediction Assignment Writeupless
Background
Using devices such as Jawbone Up, Nike FuelBand, and Fitbit it is now possible to collect a large amount of data about personal activity relatively inexpensively. These type of devices are part of the quantified self movement - a group of enthusiasts who take measurements about themselves regularly to improve their health, to find patterns in their behavior, or because they are tech geeks. One thing that people regularly do is quantify how much of a particular activity they do, but they rarely quantify how well they do it. In this project, your goal will be to use data from accelerometers on the belt, forearm, arm, and dumbell of 6 participants. They were asked to perform barbell lifts correctly and incorrectly in 5 different ways. More information is available from the website here: http://web.archive.org/web/20161224072740/http:/groupware.les.inf.puc-rio.br/har (see the section on the Weight Lifting Exercise Dataset).
Data
The training data for this project are available here:
https://d396qusza40orc.cloudfront.net/predmachlearn/pml-training.csv
The test data are available here:
https://d396qusza40orc.cloudfront.net/predmachlearn/pml-testing.csv
Loading Data, replacing empty cells and "#DIV/0!" errors by "NA" values
```{r}
pmltraining <- read.csv(
"http://d396qusza40orc.cloudfront.net/predmachlearn/pml-training.csv"
, sep=","
, na.strings=c("","#DIV/0!","NA")
)
# reading file
pmltesting <- read.csv(
"http://d396qusza40orc.cloudfront.net/predmachlearn/pml-testing.csv"
, sep=","
, na.strings=c("","#DIV/0!","NA")
)
# reading file
```
Loading only complete data and ignoring first seven attributes, wich do not contain valueable data for the preciction model.
```{r}
TrainingData <- pmltraining[,complete.cases(t(pmltraining))]
TrainingData <- TrainingData[, -c(1:7)]
TestingData <- pmltesting[,complete.cases(t(pmltesting))]
TestingData <- TestingData[, -c(1:7)]
```
Splitting into 60% training data and 40% test data
```{r}
set.seed(123)
library(caret)
inTrain = createDataPartition(y=TrainingData$classe, p = 0.6,list=FALSE)
training = TrainingData[inTrain,]
testing = TrainingData[-inTrain,]
```
Two methods will be applied to model the training data.
1) Random Forrest (RF)
```{r}
controlRF <- trainControl(method="cv", number=3, verboseIter=TRUE)
modelRf <- train(classe ~ ., data=training, method="rf",trControl=controlRF)
modelRfError <- confusionMatrix(predict(modelRf, newdata=testing), testing$classe)
modelRfError
```
2) Linear Discriminant Analysis (LDA)
```{r}
modelLda <- train(classe ~ ., data=training, method="lda")
modelLdaError <- confusionMatrix(predict(modelLda, newdata=testing), testing$classe)
modelLdaError
```
Selected the best Model
The accuracy of the 2 modeling methods above are:
Random Forest : 0.9921
LDA : 0.7046
Random Forest will be selected.
Apply the model for prediction
```{r}
predictTestingData <- predict(modelRf, newdata=TestingData)
predictTestingData
```