<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Cell Magic Tutorial
Interactions with MLDB occurs via a REST API. Interacting with a REST API over HTTP from a Notebook interface can be a little bit laborious if you're using a general-purpose Python library like requests directly, so MLDB comes with a Python library called pymldb to ease the pain.
pymldb does this in three ways
Step1:  And then we'll ask it for some help
Step2:  The most basic way in which the %mldb magic can help us with MLDB's REST API is by allowing us to type natural-feeling REST commands, like this one, which will list all of the available dataset types
Step3:  You can use similar syntax to run PUT, POST and DELETE queries as well.
Advanced Magic
The %mldb magic system also includes syntax to do more advanced operations like loading and querying data. Let's load the dataset from the Predicting Titanic Survival demo with a single command (after deleting it first if it's already loaded)
Step4:  And now let's run an SQL query on it
Step5:  We can get the results out as a Pandas DataFrame just as easily
Step6:  Server-Side Python Magic
Python code which is executed in a normal Notebook cell runs within the Notebook Python interpreter. MLDB supports the sending of Python scripts via HTTP for execution within its own in-process Python interpreter. Server-side python code gets access to a high-performance version of the REST API which bypasses HTTP, via an mldb.perform() function.
There's an %mldb magic command for running server-side Python code, from the comfort of your Notebook
<ASSISTANT_TASK:>
Python Code:
%reload_ext pymldb
Explanation: Cell Magic Tutorial
Interactions with MLDB occurs via a REST API. Interacting with a REST API over HTTP from a Notebook interface can be a little bit laborious if you're using a general-purpose Python library like requests directly, so MLDB comes with a Python library called pymldb to ease the pain.
pymldb does this in three ways:
the %mldb magics: these are Jupyter line- and cell-magic commands which allow you to make raw HTTP calls to MLDB, and also provides some higher-level functions. This tutorial shows you how to use them.
the Python Resource class: this is simple class which wraps the requests library so as to make HTTP calls to the MLDB API more friendly in a Notebook environment. Check out the Resource Wrapper Tutorial for more info on the Resource class.
the Python BatFrame class: this is a class that behaves like the Pandas DataFrame but offloads computation to the server via HTTP calls. Check out the BatFrame Tutorial for more info on the BatFrame.
The %mldb Magic System
Basic Magic
We'll start by initializing the %mldb magic system
End of explanation
%mldb help
Explanation: And then we'll ask it for some help
End of explanation
%mldb GET /v1/types/datasets
Explanation: The most basic way in which the %mldb magic can help us with MLDB's REST API is by allowing us to type natural-feeling REST commands, like this one, which will list all of the available dataset types:
End of explanation
%mldb DELETE /v1/datasets/titanic
%mldb loadcsv titanic https://raw.githubusercontent.com/datacratic/mldb-pytanic-plugin/master/titanic_train.csv
Explanation: You can use similar syntax to run PUT, POST and DELETE queries as well.
Advanced Magic
The %mldb magic system also includes syntax to do more advanced operations like loading and querying data. Let's load the dataset from the Predicting Titanic Survival demo with a single command (after deleting it first if it's already loaded):
End of explanation
%mldb query select * from titanic limit 5
Explanation: And now let's run an SQL query on it:
End of explanation
df = %mldb query select * from titanic
type(df)
Explanation: We can get the results out as a Pandas DataFrame just as easily:
End of explanation
%%mldb py
# this code will run on the server!
print mldb.perform("GET", "/v1/types/datasets", [], {})["response"]
Explanation: Server-Side Python Magic
Python code which is executed in a normal Notebook cell runs within the Notebook Python interpreter. MLDB supports the sending of Python scripts via HTTP for execution within its own in-process Python interpreter. Server-side python code gets access to a high-performance version of the REST API which bypasses HTTP, via an mldb.perform() function.
There's an %mldb magic command for running server-side Python code, from the comfort of your Notebook:
End of explanation
<END_TASK>