Skip to content

Commit

Permalink
Merge pull request #161 from datmo/r-example
Browse files Browse the repository at this point in the history
R script example
  • Loading branch information
asampat3090 committed May 28, 2018
2 parents 8a6299a + 003f363 commit 68475d0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
47 changes: 47 additions & 0 deletions examples/R/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# CLI + R examples

In order to run the examples, make sure that you have datmo properly installed with the latest
stable or development version. You can install it with the following command:
```
$ pip install datmo
```
*Note: Datmo installation is currently only officially supported through pip, Python's package manager. If you don't already have it installed, [you can find it here.](https://pip.pypa.io/en/stable/installing/)*

## Using the Examples
### R
1. Navigate to desired project folder or create a new one

$ mkdir MY_DATMO_PROJECT
$ cd MY_DATMO_PROJECT
2. Initialize the datmo project

$ datmo init

3. Copy/save example files within project folder (if directory, copy the contents of the directory)

$ cp /path/to/SCRIPT_NAME.R .
If the filename for the example is a directory then you can run the following

$ cp /path/to/DIRECTORY/* .
4. Open RStudio from the terminal (allows $PATH to find Datmo in MacOS)

$ open -a RStudio

5. Change your current working directory within RStudio to the root directory of your project.

This can be done either through the GUI, or with the following R Console command.

`> setwd("~/path/of/projectfolder")`

NOTE: You may find that some of the libraries requested in the script are not present, you can use
the RStudio GUI to install those packages if you run into any errors running the lines of code
in the example.

### Examples

| feature | filename(s) | Instructions |
| ------------- |:-------------:| -----|
| Create Snapshot | `snapshot_create_iris_caret.R`| (1) Run `snapshot_create_iris_caret.R` <br> (2) See snapshot created with `$ datmo snapshot ls` |
28 changes: 28 additions & 0 deletions examples/R/snapshot-create-iris-caret.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
library(datasets)
library(caret)
library(rpart.plot)

## Import data
df <- iris
head(df) # View first few rows of dataset

## Fit Model
modFit <- train(Species ~., method = "rpart", data=df) #Fit model
print(modFit$finalModel) #Summarize model

# Visualize Results
rpart.plot(modFit$finalModel) #create decision tree visualization

## Define the properties we want to log in the snapshot
# Define configuration to save
config<- paste(sep="",
" --config method:", modFit$method,
" --config modelType:", modFit$modelType)

#define metrics to save from the model
stats<- paste(sep="",
" --stats Accuracy:", modFit$results$Accuracy[1],
" --stats Kappa:", modFit$results$Kappa[1])

# Create snapshot with configuration and stats
system2("datmo", args=paste("snapshot create", "-m 'Whoah, my first snapshot!'", config, stats))
22 changes: 18 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ $ pip install datmo
```

## Using the Examples
### CLI flow
See [CLI flow examples](/examples/cli) for instructions
### CLI (Standalone)
The datmo CLI can work entirely as a standalone tool. It can also be used in conjunction with our language-specific SDKs to enhance the experience of the user and enable more granular control over model management during runtime.

See [CLI flow examples](/examples/cli) for instructions.

### Python
We offer a fully supported Python SDK, that works in conjunction with the CLI.

### CLI + Python flow
See [CLI + Python flow examples](/examples/python) for instructions

### CLI + Jupyter Notebook flow
### Jupyter Notebook (IPython)
For Python kernels, the Python SDK is compatible with Jupyter notebooks.
For running a containerized notebook environment, the user can do this with the CLI.

See [CLI + Jupyter Notebook flow examples](/examples/jupyter_notebook) for instructions

### R (beta)
Users can call the CLI natively using the `system2()` command in R, allowing for granular control over snapshot creation.
In the future, these system calls will be replaced with a more intuitive SDK.

See [R flow examples](/examples/R) for instructions

## Examples
Listed below are actions you might want to take with Datmo. For each
Expand All @@ -31,6 +43,8 @@ each example.
* snapshot_create_iris_sklearn
* [CLI + Jupyter Notebook flow](/examples/jupyter_notebook)
* snapshot_create_iris_sklearn
* [CLI + R flow](/examples/R)
* snapshot_create_iris_caret

#### Running a containerized task (with option to create Snapshot)
* [CLI + Python flow](/examples/python)
Expand Down

0 comments on commit 68475d0

Please sign in to comment.