Skip to content

Commit 070fc0d

Browse files
committed
initial commit
0 parents  commit 070fc0d

75 files changed

Lines changed: 6646 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.idea
2+
*.pyc
3+
*~
4+
*.ckpt
5+
.Rproj.user
6+
*_cache
7+
cifar-10-batches-py
8+
saver

‎README.html‎

Lines changed: 246 additions & 0 deletions
Large diffs are not rendered by default.

‎README.md‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Machine Learning with TensorFlow(R version)
2+
3+
4+
5+
[This](https://github.com/haven-jeon/TensorFlow-Book-R) is the unofficial code repository for [Machine Learning with TensorFlow](http://www.tensorflowbook.com/) with **R**.
6+
7+
This repository may contain different experiment R code.
8+
9+
10+
이 저장소는 R 기반의 텐서플로우로 텐서플로의 모든 기능을 활용할 수 있고, 더불어 R만의 장점을 가질수 있는 부분이 있음을 개인적으로 코드작성을 통해 알아기기 위한 목적으로 작성되었으며, 기존 책의 코드에서 부분적으로 개선되거나 실험된 코드가 포함될 수 있음을 알려드립니다.
11+
12+
13+
# Requirement
14+
15+
- [TensorFlow](https://www.tensorflow.org/) (> 1.0)
16+
- [Python](https://www.python.org/) (> 3.4)
17+
- [tensorflow](https://cran.r-project.org/package=tensorflow)
18+
- [reticulate](https://cran.r-project.org/package=reticulate)
19+
20+
# Summary
21+
22+
## [Chapter 2](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch02_basics) - TensorFlow Basics
23+
24+
- **Concept 1**: Defining tensors
25+
- **Concept 2**: Evaluating ops
26+
- **Concept 3**: Interactive session
27+
- **Concept 4**: Session loggings
28+
- **Concept 5**: Variables
29+
- **Concept 6**: Saving variables
30+
- **Concept 7**: Loading variables
31+
- **Concept 8**: TensorBoard
32+
33+
## [Chapter 3](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch03_regression) - Regression
34+
35+
- **Concept 1**: Linear regression
36+
- **Concept 2**: Polynomial regression
37+
- **Concept 3**: Regularization
38+
39+
## [Chapter 4](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch04_classification) - Classification
40+
41+
- **Concept 1**: Linear regression for classification
42+
- **Concept 2**: Logistic regression
43+
- **Concept 3**: 2D Logistic regression
44+
- **Concept 4**: Softmax classification
45+
46+
## [Chapter 5](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch05_clustering) - Clustering (_working_)
47+
48+
- **Concept 1**: Clustering
49+
- **Concept 2**: Segmentation
50+
- **Concept 3**: Self-organizing map
51+
52+
## [Chapter 6](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch06_hmm) - Hidden markov models
53+
54+
- **Concept 1**: Forward algorithm
55+
- **Concept 2**: Viterbi decode
56+
57+
## [Chapter 7](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch07_autoencoder) - Autoencoders (_working_)
58+
59+
- **Concept 1**: Autoencoder
60+
- **Concept 2**: Applying an autoencoder to images
61+
- **Concept 3**: Denoising autoencoder
62+
63+
## [Chapter 8](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch08_rl) - Reinforcement learning (_working_)
64+
65+
- **Concept 1**: Reinforcement learning
66+
67+
## [Chapter 9](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch09_cnn) - Convolutional Neural Networks
68+
69+
- **Concept 1**: Using CIFAR-10 dataset
70+
- **Concept 2**: Convolutions
71+
- **Concept 3**: Convolutional neural network
72+
- **Concept 4**: Convolutional neural network model debugging(2), **Newly added**
73+
74+
## [Chapter 10](https://github.com/haven-jeon/TensorFlow-Book-R/tree/master/ch10_rnn) - Recurrent Neural Network(_working_)
75+
76+
- **Concept 1**: Loading timeseries data
77+
- **Concept 2**: Recurrent neural networks
78+
- **Concept 3**: Applying RNN to real-world data for timeseries prediction
79+

‎TensorFlow-Book-R.Rproj‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "Ch 02: Concept01 Defining Tensors"
3+
output: github_document
4+
---
5+
6+
Import TensorFlow and Numpy:
7+
8+
```{r}
9+
library(tensorflow)
10+
library(reticulate)
11+
use_python("/usr/bin/python3")
12+
13+
np <- import("numpy",convert = F)
14+
py <- import_builtins()
15+
```
16+
17+
18+
Now, define a 2x2 matrix in different ways:
19+
20+
21+
```{r}
22+
23+
m1 <- matrix(c(1.0, 2.0,
24+
3.0, 4.0), byrow=T, nrow=2)
25+
26+
m2 <- np$array(matrix(c(1.0,2.0,
27+
3.0,4.0),
28+
byrow=2, nrow = 2),
29+
dtype=np$float32)
30+
31+
m3 <- tf$constant(matrix(c(1.0, 2.0,
32+
3.0, 4.0), byrow=T, nrow=2))
33+
34+
35+
class(m1)
36+
py$type(m2)
37+
py$type(m3)
38+
39+
```
40+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Ch 02: Concept01 Defining Tensors
2+
================
3+
4+
Import TensorFlow and Numpy:
5+
6+
``` r
7+
library(tensorflow)
8+
library(reticulate)
9+
use_python("/usr/bin/python3")
10+
11+
np <- import("numpy",convert = F)
12+
py <- import_builtins()
13+
```
14+
15+
Now, define a 2x2 matrix in different ways:
16+
17+
``` r
18+
m1 <- matrix(c(1.0, 2.0,
19+
3.0, 4.0), byrow=T, nrow=2)
20+
21+
m2 <- np$array(matrix(c(1.0,2.0,
22+
3.0,4.0),
23+
byrow=2, nrow = 2),
24+
dtype=np$float32)
25+
26+
m3 <- tf$constant(matrix(c(1.0, 2.0,
27+
3.0, 4.0), byrow=T, nrow=2))
28+
29+
30+
class(m1)
31+
```
32+
33+
## [1] "matrix"
34+
35+
``` r
36+
py$type(m2)
37+
```
38+
39+
## <class 'numpy.ndarray'>
40+
41+
``` r
42+
py$type(m3)
43+
```
44+
45+
## <class 'tensorflow.python.framework.ops.Tensor'>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Ch 02: Concept 02"
3+
output: github_document
4+
---
5+
6+
7+
# Evaluating ops
8+
9+
10+
Import TensorFlow:
11+
12+
```{r}
13+
library(tensorflow)
14+
```
15+
16+
17+
Start with a 1x2 matrix:
18+
```{r}
19+
x <- tf$constant(matrix(c(1, 2), nrow=1))
20+
```
21+
22+
23+
Let's negate it. Define the negation op to be run on the matrix:
24+
```{r}
25+
neg_x <- tf$negative(x)
26+
```
27+
28+
It's nothing special if you print it out. In fact, it doesn't even perform the negation computation. Check out what happens when you simply print it:
29+
```{r}
30+
print(neg_x)
31+
```
32+
You need to summon a session so you can launch the negation op:
33+
```{r}
34+
with(tf$Session() %as% sess, {
35+
result <- sess$run(neg_x)
36+
print(result)
37+
})
38+
```
39+
40+
41+
42+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Ch 02: Concept 02
2+
================
3+
4+
Evaluating ops
5+
==============
6+
7+
Import TensorFlow:
8+
9+
``` r
10+
library(tensorflow)
11+
```
12+
13+
Start with a 1x2 matrix:
14+
15+
``` r
16+
x <- tf$constant(matrix(c(1, 2), nrow=1))
17+
```
18+
19+
Let's negate it. Define the negation op to be run on the matrix:
20+
21+
``` r
22+
neg_x <- tf$negative(x)
23+
```
24+
25+
It's nothing special if you print it out. In fact, it doesn't even perform the negation computation. Check out what happens when you simply print it:
26+
27+
``` r
28+
print(neg_x)
29+
```
30+
31+
## Tensor("Neg:0", shape=(1, 2), dtype=float64)
32+
33+
You need to summon a session so you can launch the negation op:
34+
35+
``` r
36+
with(tf$Session() %as% sess, {
37+
result <- sess$run(neg_x)
38+
print(result)
39+
})
40+
```
41+
42+
## [,1] [,2]
43+
## [1,] -1 -2
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: "Ch 02: Concept 03"
3+
output: github_document
4+
---
5+
6+
7+
# Interactive session
8+
9+
Interactive sessions are another way to use a session. Go ahead and define one:
10+
11+
```{r}
12+
library(tensorflow)
13+
sess <- tf$InteractiveSession()
14+
```
15+
16+
We have a matrix we want to invert:
17+
```{r}
18+
x <- tf$constant(matrix(c(1.0, 2.0), nrow=1, byrow=T))
19+
neg_op <- tf$negative(x)
20+
```
21+
22+
Since we're using an interactive session, we can just call the eval() method on the op.
23+
```{r}
24+
result <- neg_op$eval()
25+
26+
print(result)
27+
```
28+
29+
30+
That code's a little cleaner when using Jupyter notebooks (like this one).
31+
32+
Don't forget to close the session:
33+
34+
```{r}
35+
sess$close()
36+
```
37+
38+
39+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Ch 02: Concept 03
2+
================
3+
4+
Interactive session
5+
===================
6+
7+
Interactive sessions are another way to use a session. Go ahead and define one:
8+
9+
``` r
10+
library(tensorflow)
11+
sess <- tf$InteractiveSession()
12+
```
13+
14+
We have a matrix we want to invert:
15+
16+
``` r
17+
x <- tf$constant(matrix(c(1.0, 2.0), nrow=1, byrow=T))
18+
neg_op <- tf$negative(x)
19+
```
20+
21+
Since we're using an interactive session, we can just call the eval() method on the op.
22+
23+
``` r
24+
result <- neg_op$eval()
25+
26+
print(result)
27+
```
28+
29+
## [,1] [,2]
30+
## [1,] -1 -2
31+
32+
That code's a little cleaner when using Jupyter notebooks (like this one).
33+
34+
Don't forget to close the session:
35+
36+
``` r
37+
sess$close()
38+
```

0 commit comments

Comments
 (0)