Phuc Ho
Front end developer
October 22, 2020 • 2 min read
We are excited to announce the release of Aito Python SDK 0.4.0 which makes predicting with Aito easier than ever. In this new version, we've added new commands to the Aito CLI: search
, predict
, recommend
, evaluate
, similarity
, match
, relate
, and query
that help you send the query to the Aito API Endpoint without having to write the curl command yourself, a full changelog is available here. This post will cover an example on how to make your first prediction with the new Aito CLI's predict
command. Let's start!
Before getting to the heart of the matter, the following things need to be prepared.
This post will use a sample data set from the Titanic data from Kaggle. You can download the example data train.csv
here. Feel free to use your own data if you have any.
Here is the snapshot of the example data:
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked |
---|---|---|---|---|---|---|---|---|---|---|---|
3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26 | 0 | 0 | STON/O2. 3101282 | 7.925 | S | |
4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35 | 1 | 0 | 113803 | 53.1 | C123 | S |
5 | 0 | 3 | Allen, Mr. William Henry | male | 35 | 0 | 0 | 373450 | 8.05 | S |
As can be seen from the table, the data includes passenger info such as name, sex, age, class and so on. Let's say we want to predict the survival chance of one specific passenger, we can use these info to describe a passenger. Please note that the value we want to predict has to be included in the data as a column, which is Survived
in this case.
The Aito CLI tool requires Python 3.6 or higher installed. Documentation is available here
Install Aito CLI
pip install aitoai
After this, you can run aito --help
to get general information on the Aito CLI tool.
Now with the data in hand and Aito CLI installed, you can start your first prediction with Aito and I promise it will be done in a blink of an eye.
1. Configure the CLI
You will need to provide your instance URL and API key to access your instance from the Aito CLI tool. You can do this by running:
aito configure
The command line will ask you to fill in the instance URL and API key, copy them from the Console and you are good to go.
2. Upload data
Then you will need to add your data table into Aito with the following command.
aito quick-add-table -n Titanic train.csv
aito quick-add-table
will infer a table schema based on the given file, create a table and upload the file content to the created table. In this case, I used the option -n TABLE_NAME
to specify that I want my table to be named Titanic
, if you do not specify that, the file name will be used. For more information on this command, check aito quick-add-table -h
3. Predict!
Next, use the new predict
command.
aito predict '{"from": "Titanic", "where": {"Age": 30, "Sex": "male"}, "predict": "Survived"}'
This predict
command is followed by an Aito query, which has similar clauses as SQL query language like from
and where
. Let's translate the query to human-readable language: predict
the Survival
of passengers whose Sex
is male
and at the Age
of 30
using data from
table Titanic
. You can try to change the passenger attributes to see how it affects the result.
The query will then be sent to /api/v1/_predict
API endpoint and Aito will return the following result.
{
"offset": 0,
"total": 2,
"hits": [
{
"$p": 0.8106108369824419,
"field": "Survived",
"feature": 0
},
{
"$p": 0.18938916301755815,
"field": "Survived",
"feature": 1
}
]
}
The result can be explained as follows: there is a 81% chance that a male passenger at the age of 30 didn't survive, and 19% chance for that passenger to survive.
Above is how to make predictions with our latest version of Aito Python SDK 0.4.0. Feel free to give it a try with your own data and join our Slack for any further discussion or feedback. Cheers!
Back to blog listEpisto Oy
Putouskuja 6 a 2
01600 Vantaa
Finland
VAT ID FI34337429