Managing feature groups with assetframe-lib for Python (beta)
Managing feature groups with assetframe-lib for Python (beta) You can use the assetframe-lib to create, view and edit feature group information for data assets in Watson Studio notebooks. Feature groups define additional metadata on columns of your data asset that can be used in downstream Machine Learning tasks. See [Managing feature groups](https://dataplatform.cloud.ibm.com/docs/content/wsj/manage-data/feature-group.html) for more information about using feature groups in the UI. Setting up the assetframe-lib and ibm-watson-studio-lib libraries The assetframe-lib library for Python is pre-installed and can be imported directly in a notebook in Watson Studio. However, it relies on the [ibm-watson-studio-lib](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/using-ibm-ws-lib.html) library. The following steps describe how to set up both libraries. To insert the project token to your notebook: 1. Click the More icon on your notebook toolbar and then click Insert project token. If a project token exists, a cell is added to your notebook with the following information: from ibm_watson_studio_lib import access_project_or_space wslib = access_project_or_space({"token":"<ProjectToken>"}) <ProjectToken> is the value of the project token. If you are told in a message that no project token exists, click the link in the message to be redirected to the project's Access Control page where you can create a project token. You must be eligible to create a project token. To create a project token: 1. From the Manage tab, select the Access Control page, and click New access token under Access tokens. 2. Enter a name, select Editor role for the project, and create a token. 3. Go back to your notebook, click the More icon on the notebook toolbar and then click Insert project token. 2. Import assetframe-lib and initialize it with the created ibm-watson-studio-lib instance. from assetframe_lib import AssetFrame AssetFrame._wslib = wslib The assetframe-lib functions and methods The assetframe-lib library exposes a set of functions and methods that are grouped in the following way: * [Creating an asset frame](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=encreate-assetframe) * [Creating, retrieving and removing features](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=encreate-features) * [Specifying feature attributes](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=enspecify-featureatt) * [Role](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=enrole) * [Description](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=endescription) * [Fairness information for favorable and unfavorable outcomes](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=enfairnessinfo) * [Fairness information for monitored and reference groups](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=enmonitoredreference) * [Value descriptions](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=envalue-desc) * [Recipe](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=enrecipe) * [Tags](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=entags) * [Previewing data](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=enpreview-data) * [Getting fairness information](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/py_assetframe.html?context=cdpaas&locale=enget-fairness) Creating an asset frame An asset frame is used to define feature group metadata on an existing data asset or on a pandas DataFrame. You can have exactly one feature group for each asset. If you create an asset frame on a pandas DataFrame, you can store the pandas DataFrame along with the feature group metadata as a data asset in your project. You can use one of the following functions to create your asset frame: * AssetFrame.from_data_asset(asset_name, create_default_features=False) This function creates a new asset frame wrapping an existing data asset in your project. If there is already a feature group for this asset, for example created in the user interface, it is read from the asset metadata. Parameters: - asset_name: (Required) The name of a data asset in your project. - create_default_features: (Optional) Creates features for all columns in the data asset. * AssetFrame.from_pandas(name, dataframe, create_default_features=False) This function creates a new asset frame wrapping a pandas DataFrame. Parameters: * name: (Required) The name of the asset frame. This name will be used as the name of the data asset if you store your feature group in your project in a later step. * dataframe: (Required) A pandas DataFrame that you want to store along with feature group information. * create_default_features: (Optional) Create features for all columns in the dataframe. Example of creating a asset frame from a pandas DataFrame: Create an asset frame from a pandas DataFrame and set the name of the asset frame. af = AssetFrame.from_pandas(dataframe=credit_risk_df, name="Credit Risk Training Data") Creating, retrieving and removing features A feature defines metadata that can be used by downstream Machine Learning tasks. You can create one feature per column in your data set. You can use one of the following functions to create, retrieve or remove columns from your asset frame: * add_feature(column_name, role='Input') This function adds a new feature to your asset frame with the given role. Parameters: * column_name: (Required) The name of the column to create a feature for. * role: (Optional) The role of the feature. It defaults to Input. Valid roles are: * Input: The input for a machine learning model * Target: The target of a prediction model * Identifier: The identifier of a row in your data set. * create_default_features() This function creates features for all columns in your data set. The roles of the features will default to Input. * get_features() This function retrieves all features of the asset frame. * get_feature(column_name) This function retrieves the feature for the given column name. Parameters: * column_name: (Required) The string name of the column to create the feature for. * get_features_by_role(role) This function retrieves all features of the dataframe with the given role. Parameters: * role: (Required) The