generated from jtr13/cctemplate
-
Notifications
You must be signed in to change notification settings - Fork 67
/
ml_packages_in_R.rmd
119 lines (86 loc) · 2.29 KB
/
ml_packages_in_R.rmd
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# (PART) Machine Learning and More {-}
# Low-key ML packages in R
## Vedant Kumar and Siddhant Kumar
### Nuralnet Package in R
```{r}
library("neuralnet")
library(quantmod)
```
```{r}
# creating training data set
weight=c(120,80,55,100,75,60)
height=c(150,165,155,175,145,170)
obese=c(1,0,0,1,1,0)
df=data.frame(weight,height,obese)
```
```{r}
# fit neural network
nn=neuralnet(obese~weight + height,data=df, hidden=3,act.fct = "logistic",
linear.output = FALSE)
# - obese~weight + height, Placed is label(dependent variable) and
#weight and height are features (independent variable).
# - df is dataframe,
# - hidden = 3: represents single layer with 3 neurons.
# - act.fct = "logistic" is the activation function
```
```{r}
# plot neural network
plot(nn)
```
```{r}
#prepare a test data
weight=c(130,90)
height=c(130,185)
df_test=data.frame(weight,height)
```
```{r}
## Prediction using neural network
Predict=compute(nn,df_test)
prob = Predict$net.result
pred = ifelse(prob>0.5, 1, 0)
print(pred)
```
#Part 1 - quantmod Package in R
```{r}
#download the price data for Apple Inc.
getSymbols("AAPL")
```
```{r}
#add parameters to the getSymbols() function and view the data using the head() function.
getSymbols("AAPL",
from = "2016/12/31",
to = "2018/12/31",
periodicity = "daily")
head(AAPL)
```
```{r}
#Using financial data from multiple organisations using lapply()
stocks <-lapply(c("AAPL", "GOOG"), function(x) {getSymbols(x,
from = "2016/12/31",
to = "2018/12/31",
periodicity = "daily",
auto.assign=FALSE)} )
```
```{r}
#View the data in line and candlesticks charts
names(stocks) <- c("AAPL", "GOOG")
head(stocks$AAPL)
chart_Series(AAPL)
chartSeries(stocks$AAPL,
type="line",
subset='2017',
theme=chartTheme('white'))
```
```{r}
chartSeries(stocks$AAPL,
type="candlesticks",
subset='2017-05',
theme=chartTheme('white'))
```
```{r}
#calculation of some common financial metrics
seriesHi(stocks$AAPL)
```
```{r}
seriesLo(stocks$AAPL)
```