In this quickstart, we will be utilizing the classic Titanic dataset to determine if we would survive the infamous maiden voyage. Highlights of the quickstart include, preprocessing, model training, registry, and finally an interactive Hex app for inference. By the end of this lab you will learn how to leverage Snowpark ML, Hex's Snowpark intergration, and Snowflake's Model Registry.

Prerequisites

Head over to the Snowflake sign-up page and register for a free account. Once you've registered, you'll get an email that will bring you to Snowflake so that you can sign in.

Connecting Snowflake with Hex

If you have an existing Hex account, login in to your account and continue to the What You Will Learn section below.

Otherwise, once you've logged into your Snowflake account, simply navigate to the Data Products tab on the left and click Partner connect. In the search bar at the top, type in Hex, and you should see the Hex partner connect tile appear. Clicking on the tile will bring up a new screen, and all you have to do is to press the Connect button in the lower right corner. After this, you'll see a new screen confirming that your account has been created and from here you can click Activate.

Creating a workspace

Once activated, you'll be brought over to Hex and will be prompted to create/name your new workspace.

Workflow roadblocks

The following issues may occur if you have an existing Hex account and you're not an Admin in that org.

Unauthorized error

If you have an existing Hex account that was created with a password and username, you may run into an "Unauthorized" error when activating your workspace in Partner Connect. If this is your experience, head over to hex.tech and login with your password and username.

Plan upgrade

If you are an existing Hex user currently on a Community plan, you may encounter an issue that will prevent you from using Partner Connect. If you're unclear on what Hex plan you are on, feel free to reach out to support@hex.tech. If you are the Admin of your organization, you can see your plan under Manage plan on the Settings page. To extend a trial, email support@hex.tech with the subject "VHOL trial extension."

Role privileges

If you do not have an Editor role or higher, you won't be able to create data connections in your workspace. To upgrade your role, contact your workspace Admin. You can find out who this is by navigating to Settings -> Users & groups within your Hex workspace.

If you're still encountering issues, or encounter any issues other than the ones listed above, please contact our support team support@hex.tech with the subject "VHOL" for priority support.

What You Will Learn

What You Will Build

In this quickstart, you will create machine learning model using Snowpark ML. This model will be registered to Snowflake's Model Registry and then we will call that model for inference. At the end, we will build a Hex app that calls the newly created model to predict our likelihood of surviving the infamous maiden voyage!

Now we can move back over to Hex and get started on our project. The first thing you'll need to do is transfer the Hex project into your new or existing Hex org.

Get Hex project

Now that you've got your project, you will find yourself in the Logic view of a Hex project. The Logic view is a notebook-like interface made up of cells such as code cells, markdown cells, input parameters and more! On the far left side, you'll see a control panel that will allow you to do things like upload files, import data connections, or search your project. Before we dive into the code, we'll need to import our Snowflake connection to our project.

We can import our Snowflake data connection by heading over to the Data sources tab represented by a database icon with a lightning bolt. At the bottom of this section, you'll see a portion that says available workspace connections and you should see one that says Snowflake if you created the Hex account via Partner Connect.

If you had an existing Hex org and did not create one via Partner Connect please follow Hex documentation on creating a Snowflake connection.

Common Problems

If coming from Partner Connect or creating a new database connection, ensure that your database connection has both the Snowpark and Writeback toggle enabled. Navigate to the Settings window and select the desired Snowflake database connection.

Enable the Snowpark and Writeback toggles.

Now that you have the Hex project, let's write the data into the imported Snowflake instance. To do this, we'll use one of Hex's utility cells called the writeback cell. What this cell does is exactly what it sounds like, writes data back to a database.

Using this cell is quite simple. First we'll need choose the source data from the dataframes currently in the project that we want to write back into Snowflake. The dataframe we'll want to write back is our titanic dataframe, so we'll choose titanic from our list. The next step is to select our Snowflake connection as the warehouse that we want to write the data to. Once complete, we'll choose the database and schema, then we can name our table. For the database, choose PC_HEX_DB and use the PUBLIC schema. For the table name, use TITANIC_DATA.

NOTE: If you did not come from Partner Connect you will not see the PC_HEX_DB database and PUBLIC schema. You can create or use an existing database and schema.

Now, we can connect to our Snowflake connection that we imported earlier. To do this head over to the data sources tab on the left control panel to find your Snowflake connection. If you hover your mouse over the connection, you'll see a query option appear at the bottom. This will allow us to query this connection in an SQL cell, however, what we want to do is create a Snowpark session using this connection. Click on the dropdown next to the query button and select Get Snowpark session. What this will do is create a new cell for us with all the code needed to spin up a Snowpark session.

The cell created by this button will be positioned under the cell that is currently selected. It is best practice to have this new cell be placed right below package import cell.

Scope the Snowpark session to the appropriate database and schema. If you are using a different database and schema name, please ensure to scope the Snowpark session to the correct database and schema.

session.use_database('PC_HEX_DB')
session.use_schema("PC_HEX_DB.PUBLIC")

In this cell, we reference our Snowpark session with the variable session which is the name assigned by default. Your cells should look similar to this:

The rest of the lab can entirely be followed step-by-step from the Hex project. Any subsequent steps and explanation will be found in the Hex project itself.

Key sections of the Hex project include:

Now that we've completed going through our project, we can share this project with others! To do this:

Congratulations on making it to the end of this Lab! You've successfully perform feature engineering, trained an XGBoost model to predict the probably of survival onboard the Titanic, and logged that model to Snowflake's Model Registy. At the end, you created a Hex app that allowed users to pass in their own criteria to see if they would survive the Titanic.

What You Learned

Related Resources