-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from datmo/r-example
R script example
- Loading branch information
Showing
3 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters