Running Artemis

Running Artemis

This page will walk you through how to use Artemis in your codebase. This is a simple process that should take under 5 minutes.

Create Artemis Project File

Whether you integrate Artemis into a script or a complex codebase, you must start by creating an Artemis project file. This file specifies the project name, the entry point to your code (which script Artemis should run when launching your script or codebase), and all the files in your codebase which have Artemis anchors.

In your terminal, navigate to the directory containing your source code, and run the console command below:

artemis_labs init

Once you run this command, this will create a folder artemis_project containing single file named project.json in the directory where you ran this command. This project.json file is the project file.

Configure Artemis Project File

Once you've created your *project file, go ahead and open it in any standard text editor. You should see text which looks something like this:
{
    "name": "Artemis Project",
    "root_dir": "C:\\Users\\Users\\Documents\\MyRepository",
    "entry_point": "main.py",
    "files": []
}

Go ahead and make the following changes to this default file:

  1. Change the value of the "name" field from "Artemis Project" to any name of your liking or leave it be if you'd like
  2. Change the value of the "entry_point" field to be the relative path of the file that should be run when running your codebase
  3. Add the relative paths of any files containing Artemis anchors to the list associated with the "files" field. Note: you can use glob expressions such as "*.py" if you'd like.

Once you're done, save and exit this script.

Integrate Artemis Into Your Code

Now that you've setup your Artemis project file, you're ready to integrate it into your code! Go ahead and insert [Artemis Anchors](doc:artemis-decorators) throughout your code. If you're just getting started, try creating a fresh Python script named `my_script.py` and pasting in the code below.

❗️

Important Note

If you're using the script we provided below, make sure to update your "project.json" file with the following changes:

  1. Set your "entry_point" value to "my_script.py"
  2. Add "my_script.py" to the "files" list
import statsmodels.api as sm
import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score
import matplotlib.pyplot as plt

# @card title="Installation Notes" side-color=rgb(0,255,0) section="Overview"
''' @blockdoc
You must run the following command to install all the dependencies for this script:
```
pip install statsmodels
pip install numpy
pip install pandas
pip install sklearn
pip install matplotlib
```
***
You must also download the data from [here](https://raw.githubusercontent.com/mahesh147/Multiple-Linear-Regression/master/50_Startups.csv)
'''
# @stop

# @card title="Overview" side-color=rgb(0,255,0) section="Overview"
''' @blockdoc
This performs multiple linear regression on a startup dataset to predict profits from a number of different business metrics.
Mathematically, this estimates $$\hat{y} = \beta X$$ where $$X$$ is a matrix of features and $$\beta$$ is a vector of coefficients.
***
Here is an example snippet from this dataset:
|R&D Spend|Administration|Marketing Spend|State|Profit|
|---|---|---|---|---|
165349.2|136897.8|471784.1|New York|192261.83
162597.7|151377.59|443898.53|California|191792.06
153441.51|101145.55|407934.54|Florida|191050.39
144372.41|118671.85|383199.62|New York|182901.99
'''
# @stop

# Load the dataset
datasets = pd.read_csv('data.csv')

# Split into train and test
train_X = np.array(datasets.to_numpy()[:40, 0:3], dtype=np.float64)
train_Y = np.array(datasets.to_numpy()[:40, 4], dtype=np.float64)

test_X = np.array(datasets.to_numpy()[40:, 0:3], dtype=np.float64)
test_Y = np.array(datasets.to_numpy()[40:, 4], dtype=np.float64)

# Train the model
model = sm.OLS(train_Y,train_X)
results = model.fit()

# Predict the results
pred_Y = results.predict(test_X)

# Evaluate the results
mse = mean_squared_error(pred_Y, test_Y)
r2 = r2_score(pred_Y, test_Y)
sse = np.sum((pred_Y - test_Y)**2)

# @card title="Evaluation Metrics" side-color=rgb(0,0,255) section="Results"
''' @blockdoc
Below are the evaluation metrics for this model.
| Metric | Value |
| --- | --- |
| $$MSE$$ | <<np.round(mse, 2)>> |
| $$R^2$$ | <<np.round(r2, 5)>> |
| $$SSE$$ | <<np.round(sse, 2)>> |
'''
# @stop

# Plot prediction data points
fig = plt.figure()
plt.plot([test_Y.min(), test_Y.max()], [test_Y.min(), test_Y.max()], 'k--', lw=4)
plt.xlabel('Measured')
plt.ylabel('Predicted')
plt.title('Predicted vs. Measured')
plt.scatter(test_Y, pred_Y)

# @card title="Visualization of Results" side-color=rgb(0,0,255) section="Results"
# @doc Below is a visualization of the predicted vs. measured values.
# @output graph data=fig size=400x*

Next, download the CSV file hosted here, save it to a file named data.csv, and place it next to your file my_script.py

Launching Your Code In Artemis

Now we're ready to test our code out in Artemis! Go to your terminal and enter the following command below to launch your codebase in Artemis:
artemis_labs artemis_project

Interacting With Artemis Interface

Once you've run your code, a browser should open featuring your notebook-style user interface side-by-side with your code base. You can step through your code with the green play button, fast forward through your code with the green play button with two arrows, restart your code with the yellow reload icon, and exit Artemis with the red exit button.

If you click on cards shown in the notebook interface, they will automatically highlight the code they correspond to on the right-hand side. Likewise, if you click on code snippets on the right-hand side, it will automatically highlight the card it corresponds to.

You can view your notebook-style UI in the default flow mode, which displays cards in the order in which they were generated, or in context mode, where they are divided into drop-down sections and grouped according to their section name.