Skip to main content
This guide shows you how to define Phoenix inferences using your own data.
  • For a conceptual overview of the Phoenix API, including a high-level introduction to the notion of inferences and schemas, see here.
  • For a comprehensive description of phoenix.Dataset and phoenix.Schema, see the API reference.
Once you have a pandas dataframe df containing your data and a schema object describing the format of your dataframe, you can define your Phoenix dataset either by running
ds = px.Inferences(df, schema)
or by optionally providing a name for your dataset that will appear in the UI:
ds = px.Inferences(df, schema, name="training")
As you can see, instantiating your dataset is the easy part. Before you run the code above, you must first wrangle your data into a pandas dataframe and then create a Phoenix schema to describe the format of your dataframe. The rest of this guide shows you how to match your schema to your dataframe with concrete examples.

Predictions and Actuals

Let’s first see how to define a schema with predictions and actuals (Phoenix’s nomenclature for ground truth). The example dataframe below contains inference data from a binary classification model trained to predict whether a user will click on an advertisement. The timestamps are datetime.datetime objects that represent the time at which each inference was made in production.

Dataframe

timestampprediction_scorepredictiontarget
2023-03-01 02:02:190.91clickclick
2023-02-17 23:45:480.37no_clickno_click
2023-01-30 15:30:030.54clickno_click
2023-02-03 19:56:090.74clickclick
2023-02-24 04:23:430.37no_clickclick

Schema

schema = px.Schema(
    timestamp_column_name="timestamp",
    prediction_score_column_name="prediction_score",
    prediction_label_column_name="prediction",
    actual_label_column_name="target",
)
This schema defines predicted and actual labels and scores, but you can run Phoenix with any subset of those fields, e.g., with only predicted labels.

Features and Tags

Phoenix accepts not only predictions and ground truth but also input features of your model and tags that describe your data. In the example below, features such as FICO score and merchant ID are used to predict whether a credit card transaction is legitimate or fraudulent. In contrast, tags such as age and gender are not model inputs, but are used to filter your data and analyze meaningful cohorts in the app.

Dataframe

fico_scoremerchant_idloan_amountannual_incomehome_ownershipnum_credit_linesinquests_in_last_6_monthsmonths_since_last_delinquencyagegenderpredictedtarget
578Scammeds430062966RENT1100025malenot_fraudfraud
507Schiller Ltd2100052335RENT12902378femalenot_fraudnot_fraud
656Kirlin and Sons1800094995MORTGAGE310054femaleuncertainuncertain
414Scammeds1800032034LEASE812034malefraudnot_fraud
512Champlin and Sons2000046005OWN1481049maleuncertainuncertain

Schema

schema = px.Schema(
    prediction_label_column_name="predicted",
    actual_label_column_name="target",
    feature_column_names=[
        "fico_score",
        "merchant_id",
        "loan_amount",
        "annual_income",
        "home_ownership",
        "num_credit_lines",
        "inquests_in_last_6_months",
        "months_since_last_delinquency",
    ],
    tag_column_names=[
        "age",
        "gender",
    ],
)

Implicit Features

If your data has a large number of features, it can be inconvenient to list them all. For example, the breast cancer dataset below contains 30 features that can be used to predict whether a breast mass is malignant or benign. Instead of explicitly listing each feature, you can leave the feature_column_names field of your schema set to its default value of None, in which case, any columns of your dataframe that do not appear in your schema are implicitly assumed to be features.

Dataframe

targetpredictedmean radiusmean texturemean perimetermean areamean smoothnessmean compactnessmean concavitymean concave pointsmean symmetrymean fractal dimensionradius errortexture errorperimeter errorarea errorsmoothness errorcompactness errorconcavity errorconcave points errorsymmetry errorfractal dimension errorworst radiusworst textureworst perimeterworst areaworst smoothnessworst compactnessworst concavityworst concave pointsworst symmetryworst fractal dimension
malignantbenign15.4919.97102.40744.70.116000.156200.189100.091130.19290.067440.64701.33104.67566.910.0072690.029280.049720.016390.018520.00423221.2029.41142.101359.00.16810.39130.555300.212100.31870.10190
malignantmalignant17.0120.26109.70904.30.087720.073040.069500.053900.20260.052230.58580.85544.10668.460.0050380.015030.019460.011230.022940.00258119.8025.05130.001210.00.11110.14860.193200.109600.32750.06469
malignantmalignant17.9910.38122.801001.00.118400.277600.300100.147100.24190.078711.09500.90538.589153.400.0063990.049040.053730.015870.030030.00619325.3817.33184.602019.00.16220.66560.711900.265400.46010.11890
benignbenign14.5313.9893.86644.20.109900.092420.068950.064950.16500.061210.30600.72132.14325.700.0061330.012510.016150.011360.022070.00356315.8016.93103.10749.90.13470.14780.137300.106900.26060.07810
benignbenign10.2614.7166.20321.60.098820.091590.035810.020370.16330.070050.33802.50902.39419.330.0173600.046710.026110.012960.036750.00675810.8819.4870.89357.10.13600.16360.071620.040740.24340.08488

Schema

schema = px.Schema(
    prediction_label_column_name="predicted",
    actual_label_column_name="target",
)

Excluded Columns

You can tell Phoenix to ignore certain columns of your dataframe when implicitly inferring features by adding those column names to the excluded_column_names field of your schema. The dataframe below contains all the same data as the breast cancer dataset above, in addition to “hospital” and “insurance_provider” fields that are not features of your model. Explicitly exclude these fields, otherwise, Phoenix will assume that they are features.

Dataframe

targetpredictedhospitalinsurance_providermean radiusmean texturemean perimetermean areamean smoothnessmean compactnessmean concavitymean concave pointsmean symmetrymean fractal dimensionradius errortexture errorperimeter errorarea errorsmoothness errorcompactness errorconcavity errorconcave points errorsymmetry errorfractal dimension errorworst radiusworst textureworst perimeterworst areaworst smoothnessworst compactnessworst concavityworst concave pointsworst symmetryworst fractal dimension
malignantbenignPacific Clinicsuninsured15.4919.97102.40744.70.116000.156200.189100.091130.19290.067440.64701.33104.67566.910.0072690.029280.049720.016390.018520.00423221.2029.41142.101359.00.16810.39130.555300.212100.31870.10190
malignantmalignantQueens HospitalAnthem Blue Cross17.0120.26109.70904.30.087720.073040.069500.053900.20260.052230.58580.85544.10668.460.0050380.015030.019460.011230.022940.00258119.8025.05130.001210.00.11110.14860.193200.109600.32750.06469
malignantmalignantSt. Francis Memorial HospitalBlue Shield of CA17.9910.38122.801001.00.118400.277600.300100.147100.24190.078711.09500.90538.589153.400.0063990.049040.053730.015870.030030.00619325.3817.33184.602019.00.16220.66560.711900.265400.46010.11890
benignbenignPacific ClinicsKaiser Permanente14.5313.9893.86644.20.109900.092420.068950.064950.16500.061210.30600.72132.14325.700.0061330.012510.016150.011360.022070.00356315.8016.93103.10749.90.13470.14780.137300.106900.26060.07810
benignbenignCityMedAnthem Blue Cross10.2614.7166.20321.60.098820.091590.035810.020370.16330.070050.33802.50902.39419.330.0173600.046710.026110.012960.036750.00675810.8819.4870.89357.10.13600.16360.071620.040740.24340.08488

Schema

schema = px.Schema(
    prediction_label_column_name="predicted",
    actual_label_column_name="target",
    excluded_column_names=[
        "hospital",
        "insurance_provider",
    ],
)

Embedding Features

Embedding features consist of vector data in addition to any unstructured data in the form of text or images that the vectors represent. Unlike normal features, a single embedding feature may span multiple columns of your dataframe. Use px.EmbeddingColumnNames to associate multiple dataframe columns with the same embedding feature.
  • For a conceptual overview of embeddings, see Embeddings.
  • For a comprehensive description of px.EmbeddingColumnNames, see the API reference.
The example in this section contain low-dimensional embeddings for the sake of easy viewing. Your embeddings in practice will typically have much higher dimension.

Embedding Vectors

To define an embedding feature, you must at minimum provide Phoenix with the embedding vector data itself. Specify the dataframe column that contains this data in the vector_column_name field on px.EmbeddingColumnNames. For example, the dataframe below contains tabular credit card transaction data in addition to embedding vectors that represent each row. Notice that:
  • Unlike other fields that take strings or lists of strings, the argument to embedding_feature_column_names is a dictionary.
  • The key of this dictionary, “transaction_embedding,” is not a column of your dataframe but is name you choose for your embedding feature that appears in the UI.
  • The values of this dictionary are instances of px.EmbeddingColumnNames.
  • Each entry in the “embedding_vector” column is a list of length 4.

Dataframe

predictedtargetembedding_vectorfico_scoremerchant_idloan_amountannual_incomehome_ownershipnum_credit_linesinquests_in_last_6_monthsmonths_since_last_delinquency
fraudnot_fraud[-0.97, 3.98, -0.03, 2.92]604Leannon Ward22000100781RENT10800
fraudnot_fraud[3.20, 3.95, 2.81, -0.09]612Scammeds7500116184MORTGAGE42256
not_fraudnot_fraud[-0.49, -0.62, 0.08, 2.03]646Leannon Ward3200073666RENT13100
not_fraudnot_fraud[1.69, 0.01, -0.76, 3.64]560Kirlin and Sons1900038589MORTGAGE13100
uncertainuncertain[1.46, 0.69, 3.26, -0.17]636Champlin and Sons10000100251MORTGAGE1003

Schema

schema = px.Schema(
    prediction_label_column_name="predicted",
    actual_label_column_name="target",
    embedding_feature_column_names={
        "transaction_embeddings": px.EmbeddingColumnNames(
            vector_column_name="embedding_vector"
        ),
    },
)
The features in this example are implicitly inferred to be the columns of the dataframe that do not appear in the schema.
To compare embeddings, Phoenix uses metrics such as Euclidean distance that can only be computed between vectors of the same length. Ensure that all embedding vectors for a particular embedding feature are one-dimensional arrays of the same length, otherwise, Phoenix will throw an error.

Embeddings of Images

If your embeddings represent images, you can provide links or local paths to image files you want to display in the app by using the link_to_data_column_name field on px.EmbeddingColumnNames. The following example contains data for an image classification model that detects product defects on an assembly line.

Dataframe

defectiveimageimage_vector
okayhttps://www.example.com/image0.jpeg[1.73, 2.67, 2.91, 1.79, 1.29]
defectivehttps://www.example.com/image1.jpeg[2.18, -0.21, 0.87, 3.84, -0.97]
okayhttps://www.example.com/image2.jpeg[3.36, -0.62, 2.40, -0.94, 3.69]
defectivehttps://www.example.com/image3.jpeg[2.77, 2.79, 3.36, 0.60, 3.10]
okayhttps://www.example.com/image4.jpeg[1.79, 2.06, 0.53, 3.58, 0.24]

Schema

schema = px.Schema(
    actual_label_column_name="defective",
    embedding_feature_column_names={
        "image_embedding": px.EmbeddingColumnNames(
            vector_column_name="image_vector",
            link_to_data_column_name="image",
        ),
    },
)

Local Images

For local image data, we recommend the following steps to serve your images via a local HTTP server:
  1. In your terminal, navigate to a directory containing your image data and run python -m http.server 8000.
  2. Add URLs of the form “http://localhost:8000/rel/path/to/image.jpeg” to the appropriate column of your dataframe.
For example, suppose your HTTP server is running in a directory with the following contents:
.
└── image-data
    └── example_image.jpeg
Then your image URL would be http://localhost:8000/image-data/example_image.jpeg.

Embeddings of Text

If your embeddings represent pieces of text, you can display that text in the app by using the raw_data_column_name field on px.EmbeddingColumnNames. The embeddings below were generated by a sentiment classification model trained on product reviews.

Dataframe

nametexttext_vectorcategorysentiment
Magic LampMakes a great desk lamp![2.66, 0.89, 1.17, 2.21]officepositive
Ergo Desk ChairThis chair is pretty comfortable, but I wish it had better back support.[3.33, 1.14, 2.57, 2.88]officeneutral
Cloud Nine MattressI’ve been sleeping like a baby since I bought this thing.[2.5, 3.74, 0.04, -0.94]bedroompositive
Dr. Fresh’s Spearmint ToothpasteAvoid at all costs, it tastes like soap.[1.78, -0.24, 1.37, 2.6]personal_hygienenegative
Ultra-Fuzzy Bath MatCheap quality, began fraying at the edges after the first wash.[2.71, 0.98, -0.22, 2.1]bathnegative

Schema

schema = px.Schema(
    actual_label_column_name="sentiment",
    feature_column_names=[
        "category",
    ],
    tag_column_names=[
        "name",
    ],
    embedding_feature_column_names={
        "product_review_embeddings": px.EmbeddingColumnNames(
            vector_column_name="text_vector",
            raw_data_column_name="text",
        ),
    },
)

Multiple Embedding Features

Sometimes it is useful to have more than one embedding feature. The example below shows a multi-modal application in which one embedding represents the textual description and another embedding represents the image associated with products on an e-commerce site.

Dataframe

namedescriptiondescription_vectorimageimage_vector
Magic LampEnjoy the most comfortable setting every time for working, studying, relaxing or getting ready to sleep.[2.47, -0.01, -0.22, 0.93]https://www.example.com/image0.jpeg[2.42, 1.95, 0.81, 2.60, 0.27]
Ergo Desk ChairThe perfect mesh chair, meticulously developed to deliver maximum comfort and high quality.[-0.25, 0.07, 2.90, 1.57]https://www.example.com/image1.jpeg[3.17, 2.75, 1.39, 0.44, 3.30]
Cloud Nine MattressOur Cloud Nine Mattress combines cool comfort with maximum affordability.[1.36, -0.88, -0.45, 0.84]https://www.example.com/image2.jpeg[-0.22, 0.87, 1.10, -0.78, 1.25]
Dr. Fresh’s Spearmint ToothpasteNatural toothpaste helps remove surface stains for a brighter, whiter smile with anti-plaque formula[-0.39, 1.29, 0.92, 2.51]https://www.example.com/image3.jpeg[1.95, 2.66, 3.97, 0.90, 2.86]
Ultra-Fuzzy Bath MatThe bath mats are made up of 1.18-inch height premium thick, soft and fluffy microfiber, making it great for bathroom, vanity, and master bedroom.[0.37, 3.22, 1.29, 0.65]https://www.example.com/image4.jpeg[0.77, 1.79, 0.52, 3.79, 0.47]

Schema

schema = px.Schema(
    tag_column_names=["name"],
    embedding_feature_column_names={
        "description_embedding": px.EmbeddingColumnNames(
            vector_column_name="description_vector",
            raw_data_column_name="description",
        ),
        "image_embedding": px.EmbeddingColumnNames(
            vector_column_name="image_vector",
            link_to_data_column_name="image",
        ),
    },
)
Distinct embedding features may have embedding vectors of differing length. The text embeddings in the above example have length 4 while the image embeddings have length 5.