{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Specifying Intent in Lux" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lux provides a flexible language for communicating your analysis intent to the system, so that Lux can provide better and more relevant recommendations to you. In this tutorial, we will see different ways of specifying the intent, including the attributes and values that you are interested or not interested in, enumeration specifiers, as well as any constraints on the visualization encoding.\n", "\n", "The primary way to set the current intent associated with a dataframe is by setting the `intent` property of the dataframe, and providing a list of specification as input. We will first describe how intent can be specified through convenient shorthand descriptions as string inputs, then we will describe advance usage via the `lux.Clause` object.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import lux" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(\"../data/college.csv\")\n", "lux.config.default_display = \"lux\" # Setting default display as Lux" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Specifying attributes of interest" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can indicate that you are interested in an attribute, let's say `AverageCost`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.intent = ['AverageCost']\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You might be interested in multiple attributes, for instance you might want to look at both `AverageCost` and `FundingModel`. When multiple clauses are specified, Lux applies all the clauses in the intent and searches for visualizations that are relevant to `AverageCost` **and** `FundingModel`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.intent = ['AverageCost','FundingModel']\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's say that in addition to `AverageCost`, you are interested in the looking at a list of attributes that are related to different financial measures, such as `Expenditure` or `MedianDebt`, and how they breakdown with respect to `FundingModel`. \n", "\n", "You can specify a list of desired attributes separated by the `|` symbol, which indicates an `OR` relationship between the list of attributes. If multiple clauses are specified, Lux automatically create combinations of the specified attributes. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "possible_attributes = \"AverageCost|Expenditure|MedianDebt|MedianEarnings\"\n", "df.intent = [possible_attributes,\"FundingModel\"]\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, you could also provide the specification as a list: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "possible_attributes = ['AverageCost','Expenditure','MedianDebt','MedianEarnings']\n", "df.intent = [possible_attributes,\"FundingModel\"]\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Specifying values of interest" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In Lux, you can also specify particular values corresponding to subsets of the data that you might be interested in. For example, you may be interested in only colleges located in New England. \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.intent = [\"Region=New England\"]\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Excercise 1: " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also specify multiple values of interest using the same `|` notation that we saw earlier. \n", "\n", "For example, you might want to compare the `MedianDebt` of students from colleges in `New England`, `Southeast`, and `Far West`.\n", "Write the corresponding code to specify this intent.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "# Write code to specify the intent here\n", "# Hint: Try printing out your dataframe to see if your intent is specified correctly\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Lux supports advanced capabilities in specifying the intent, such as contraining an attribute to display on a specific axes, or modifying the aggregation or binning parameters, through the [lux.Clause](https://lux-api.readthedocs.io/en/latest/source/reference/lux.vis.html#module-lux.vis.Clause) object, which can be thought of as a single *unit* of intent. We will see some example of how lux.Clause is used thorughout the subsequent tutorials, see [this page](https://lux-api.readthedocs.io/en/latest/source/guide/intent.html#advanced-intent-specification-through-lux-clause) for more information." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }