Basic Workflow#

Objectives: what you will take away#

  • Definitions & an understanding of terminology unique to Howso Engine and what the basic workflow of using the Howso Engine looks like.

  • How-To import data, map features, train, analyze, and make inferences using the Howso Engine.

Prerequisites: before you begin#

Installation

Data#

Our example dataset for this recipe is the well known Adult dataset. It is accessible via the pmlb package installed earlier. We use the fetch_data() function to retrieve the dataset in Step 1 below.

Concepts & Terminology#

Howso Engine is a generalized Machine Learning (ML) and Artificial Intelligence platform that creates powerful decision-making models that are fully explainable, auditable, and editable. Howso Engine uses Instance-Based Machine Learning which stores instances, i.e., data points, in memory and makes predictions about new instances given their relationship to existing instances. This technology harnesses a fast spatial query system and information theory for performance and accuracy.

Notebook Recipe#

The following recipe will demonstrate some of the capabilities demonstrated in this guide as well as a few additional capabilities.

How-To Guide#

Here we will walk through the steps of what a basic workflow might look like when using Howso Engine. First, we will load data into a pandas DataFrame for use with Howso Engine. Then, we will use the Howso Engine to map attributes of the features, train a trainee, analyze, and react.

[1]:
import pandas as pd
from pmlb import fetch_data

from howso.engine import Trainee
from howso.utilities import infer_feature_attributes

Step 1 - Load Data and Infer Feature Attributes#

First, we load the adult dataset from the PMLB repository. This dataset consists of 15 features, which will have their attributes inferred by infer_feature_attributes(). This will determine attributes about each feature including bounds, allowed values, and feature type. Before the following steps, the inferred feature attributes should be inspected to ensure their correctness.

[2]:
df = fetch_data('adult').sample(1_000)
features = infer_feature_attributes(df)

features.to_dataframe()
[2]:
type decimal_places bounds data_type original_type
min max allow_null observed_min observed_max data_type size
age continuous 0 0.0 123.0 True 17.0 81.0 number numeric 8
workclass nominal 0 NaN NaN False NaN NaN number integer 8
fnlwgt continuous 0 0.0 1843300.0 True 19302.0 1125613.0 number numeric 8
education nominal 0 NaN NaN False NaN NaN number integer 8
education-num continuous 0 0.0 26.0 True 1.0 16.0 number numeric 8
marital-status nominal 0 NaN NaN False NaN NaN number integer 8
occupation nominal 0 NaN NaN False NaN NaN number integer 8
relationship nominal 0 NaN NaN False NaN NaN number integer 8
race nominal 0 NaN NaN False NaN NaN number integer 8
sex nominal 0 NaN NaN False NaN NaN number integer 8
capital-gain continuous 0 0.0 164870.0 True 0.0 99999.0 number numeric 8
capital-loss continuous 0 0.0 4953.0 True 0.0 3004.0 number numeric 8
hours-per-week continuous 0 0.0 162.0 True 2.0 99.0 number numeric 8
native-country nominal 0 NaN NaN False NaN NaN number integer 8
target nominal 0 NaN NaN False NaN NaN number integer 8

Step 2 - Create the Trainee, Train, and Analyze#

A Trainee is similar in function to a model in other machine learning paradigms, but is not locked to any particular use-case or to predicting a particular feature. Note that both the data and the feature attributes are supplied at this time. Since the feature attributes are essentially a part of the training data it is extremely important to ensure they are correct.

[3]:
trainee = Trainee(features=features)
trainee.train(df)

After the data are trained, we can Trainee.analyze() the Trainee. This method will determine the best hyperparameters for the data and cache some important values that are used to ensure the highest model performance. By default, Trainee.analyze() will optimize the Trainee’s parameters for any possible target feature.

[4]:
trainee.analyze()

Step 3 - React#

Now that the Trainee has been prepared, it is ready for use. A common use-case, determining how well a model performs when predicting the dataset, can be done with a single call to the Trainee:

[5]:
prediction_stats = trainee.get_prediction_stats(
    action_feature="target",
    details={"prediction_stats": True},
)
prediction_stats
[5]:
education-num age fnlwgt hours-per-week capital-gain capital-loss marital-status relationship native-country workclass occupation sex race education target
spearman_coeff 0.967739 0.533649 0.043573 0.391516 0.520104 0.598342 NaN NaN NaN NaN NaN NaN NaN NaN NaN
accuracy NaN NaN NaN NaN NaN NaN 0.799000 0.720000 0.914228 0.766000 0.303000 0.763000 0.850000 1.0 0.848000
r2 0.940469 0.331705 -0.028898 0.130382 0.085908 0.001847 NaN NaN NaN NaN NaN NaN NaN NaN NaN
adjusted_smape 1.921818 21.777893 43.739437 20.009342 130.185326 88.687304 NaN NaN NaN NaN NaN NaN NaN NaN NaN
precision NaN NaN NaN NaN NaN NaN 0.401786 0.575883 0.075033 0.394778 0.208294 0.735738 0.533688 1.0 0.792897
mcc NaN NaN NaN NaN NaN NaN 0.697187 0.614244 0.290795 0.446359 0.222915 0.455323 0.322299 1.0 0.550669
mae 0.113799 8.479986 76717.905664 7.673994 1678.128786 159.739313 0.251066 0.344574 0.144452 0.367232 0.773128 0.261809 0.227599 0.0 0.211775
smape 2.138823 22.080957 43.739581 20.300178 136.389464 89.304256 NaN NaN NaN NaN NaN NaN NaN NaN NaN
recall NaN NaN NaN NaN NaN NaN 0.410305 0.458878 0.080040 0.344927 0.226369 0.719862 0.310573 1.0 0.758825
missing_value_accuracy NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
rmse 0.639135 10.984942 105975.703035 11.245206 7710.624515 410.144544 NaN NaN NaN NaN NaN NaN NaN NaN NaN

An action_feature is the same as a target feature or dependent variable. This call will compute a number of different statistics, including accuracy, precision, recall, \(R^2\), and others. Rather than performing a train-test split, which is common with other machine learning techniques, the Trainee uses leave-one-out to provide a more comprehensive understanding of the data. More traditional approaches can still be used with the Trainee.react() method.

API References#