--- title: "Bayesian Training Guide" slug: "bayesian-training-guide" updated: 2026-11-06T14:56:16Z published: 2026-11-06T14:56:16Z canonical: "knowledge.curiositysoftware.ie/bayesian-training-guide" --- > ## Documentation Index > Fetch the complete documentation index at: https://knowledge.curiositysoftware.ie/llms.txt > Use this file to discover all available pages before exploring further. # Bayesian Training Guide This guide covers everything you need to train a **bayesian_network** model and use it to generate synthetic data with the same characteristics as your source data. | Section | What it covers | | --- | --- | | [1. Training](/docs/bayesian-training-guide#1-training) | Step-by-step: create the activity and train a model | | [2. Engine](/docs/bayesian-training-guide#2-engine) | What a Bayesian network is, how it works and when to choose it | | [3. Hyperparameters](/docs/bayesian-training-guide#3-hyperparameters) | Activity settings and every bayesian_network parameter, with tuning advice | | [4. Model](/docs/bayesian-training-guide#4-model) | What training produces, how to read the log and when to retrain | | [5. Column Inclusion / Exclusion Guide](/docs/bayesian-training-guide#5-column-inclusion-exclusion-guide) | Which columns to train on and which to leave out | | [6. Generate and Validate](/docs/bayesian-training-guide#6-generate-and-validate) | Generating data, checking it against the source and fixing issues | New to Bayesian networks? Follow section 1 first. It links to the other sections wherever you need more detail. --- ## The example dataset > **New to machine learning?** Load our [ML Sample Dataset - Lending](/kb/docs/ml-sample-dataset-lending) into your database first, then work through this guide with the `CUSTOMER` table on its own, then add the other tables once you're comfortable. The examples in this guide use the `CUSTOMER` table from a synthetic consumer-lending dataset. It has 12,000 rows, one per customer, and 11 columns: | Column | Type | What it holds | | --- | --- | --- | | `customer_id` | Text | Unique identifier, e.g. `C000001` | | `open_date` | Date | When the customer relationship started | | `tenure_months` | Whole number | Months since `open_date` (0–127) | | `age_band` | Category | Six bands, `18-24` to `65+` | | `income_band` | Category | Five bands. About 7% of values are missing | | `employment_cd` | Category | `FULLTIME`, `PARTTIME`, `SELFEMP`, `CONTRACT`, `RETIRED` | | `region_cd` | Category | Eight regions across Ireland and the UK | | `channel_cd` | Category | `BRANCH`, `ONLINE` or `BROKER` | | `credit_score` | Whole number | 473–850 | | `credit_limit` | Decimal | 1,000–40,000, in steps of 500 | | `dti_ratio` | Decimal | Debt-to-income ratio, 0.05–0.65 | It mixes categories, whole numbers and decimals, includes missing values, and has strong relationships between columns. For example, customers with higher credit scores have higher credit limits. Those are the things you'll check the synthetic data for. --- ## 1. Training **Before you start, you need:** - A connection to your source database, scanned into the **Data Dictionary** - A **Database Definition** built from that connection ### Create the data activity **1. Create a Machine Learning data activity.** Go to **Data Activities** and create a new activity of type **Machine Learning**. **2. Add a name and description.** Use a name you'll recognise later, such as `Customer – Bayesian`. In the description, note the table and engine you're training. **3. Select a Database Definition and rule set.** Select your **Database Definition**, then choose **New Rule Set**. If you already have a training rule set for this data, choose **Existing Rule Set** instead. ### Configure the activity **4. Select the source connection.** On the **Configuration** tab, select the **Source Connection** the training data is read from. **5. Leave Find Rules off.** It adds significant training time, and on a first run you want to confirm that everything completes. See [Activity settings](/docs/bayesian-training-guide#activity-settings). **6. Set Imputation Strategy to Random Sample.** It keeps each column's real proportions and works for every column type. See [Activity settings](/docs/bayesian-training-guide#activity-settings). **7. Set Generative Engine to bayesian_network.** See [2. Engine](/docs/bayesian-training-guide#2-engine) for why you'd choose it. **8. Set the engine parameters.** Choose a `struct_learning_search_method` to suit your data. See [Search methods](/docs/bayesian-training-guide#search-methods) for the options. The example uses **tree_search**, with the other values in [Example values](/docs/bayesian-training-guide#example-values). ### Choose tables and columns **9. Select your tables.** On the **Tables** tab, check the table(s) you want and click **Add Selected**. Start with one table. It's the quickest way to confirm everything works before you add related tables. **10. Finish the wizard.** Click **Next**, then **Finish**. Your new data activity opens. **11. Run Analyze (optional).** From the **Actions** panel, choose **Analyze**. It confirms the data can be read and suggests post-processing rules, such as the valid range of each numeric column. Relationship suggestions only appear when your rule set includes related tables. See [Analyze](/kb/docs/machine-learning-extras#analyze). **12. Set which columns are active.** Open your training rule set and expand your table. Make repeated information inactive, and any identifier that no other table points to. In the example, the `CUSTOMER` table is trained on its own, so `customer_id` and `open_date` are inactive. The table's primary key is still read during training, even when it's inactive, so the platform can keep track of rows. If you train related tables together, keep the key columns that link them active. See [5. Column Inclusion / Exclusion Guide](/docs/bayesian-training-guide#5-column-inclusion-exclusion-guide). **13. Check the table-level engine (optional).** Each table in the rule set uses the engine from the Configuration tab unless you set a different one for it. To use a different engine or different parameters for one table, edit the table and set them there. A table-level engine overrides the Configuration tab for that table. ### Train **14. Train the model.** Go back to the dashboard and select **Train Model**. **15. Check the log.** Shortly after training starts, open the job log and find the line beginning `Fit internal model`. Confirm it says `bayesian_network` and shows the parameters you set. If it doesn't, stop the job and check steps 7 and 13. See [Reading the training log](/docs/bayesian-training-guide#reading-the-training-log). When training finishes, the model is attached to the activity and its output files are available to download. See [4. Model](/docs/bayesian-training-guide#4-model). --- ## 2. Engine ### What a Bayesian network is A Bayesian network describes your data as a set of columns that depend on each other. It has two parts: - **The structure** is a graph showing which columns depend on which. For example, it might learn that `credit_limit` depends on `income_band`. - **The probabilities** say how likely each value of a column is, given the values of the columns it depends on. For example, how likely each credit limit is for a customer in the `100K+` income band. Training happens in two stages: 1. **Structure learning.** The engine searches for the graph that best fits your data. The search method is set by `struct_learning_search_method`. See [Search methods](/docs/bayesian-training-guide#search-methods). 2. **Probability learning.** For each column, it counts how often each value appears alongside each value of the columns it depends on. To generate a row, the engine works through the graph. It picks a value for each column at random, using the probabilities for the values already picked. The result is a new row that follows the same patterns as your real data, but isn't a copy of any real row. ### How numbers are handled A Bayesian network treats each distinct value of a column as one possible outcome. A numeric column with 338 different values, such as `credit_score` in the example, is learned as 338 outcomes. When generating, the engine picks one of those values, then adds a small random amount controlled by `encoder_noise_scale`. Whole-number columns, such as `tenure_months` and `credit_score`, are converted back to whole numbers when the output is written. How many distinct values your columns have affects which search method suits your data. See [Search methods](/docs/bayesian-training-guide#search-methods). ### How bayesian_network compares with the other engines | | bayesian_network | tvae | ctgan | | --- | --- | --- | --- | | Type | Probability graph | Neural network (autoencoder) | Neural network (two competing networks) | | Best for | Small to medium tables where you want to see the relationships | Small to medium tables with mixed categories and numbers | Imbalanced data with many categories | | Training stability | Good | Good | Can be unstable | | Speed (platform rating) | 8/10 | 7/10 | 6/10 | | Can you see what it learned? | Yes, as a graph of dependencies | No | No | ### When to choose bayesian_network Choose bayesian_network when: - Your table is mostly categories, codes and bands, with some numbers - You want a fast first result, or you're training on CPU - You want to see which columns depend on which Choose something else when: - Your table is large, with many columns or many distinct values per column. Try **tvae** or **ctgan**. - One or more category columns are very imbalanced (a rare value in under 1% of rows) and must still appear. Try **ctgan**. ### Global engine vs table-level engine You can set the engine in two places: - **Configuration tab:** the default engine for the activity. - **Table level, in the training rule set:** the engine for that table. The table-level setting wins. Leave it blank to use the Configuration tab engine, or set it to use a different engine for one table. Confirm which engine each table used in the log (see [Reading the training log](/docs/bayesian-training-guide#reading-the-training-log)). ### Training related tables When you train more than one table, keep the key columns that link the tables active: each foreign key, and the primary key it points to. They're what lets each child row link to the right parent. The engine from the Configuration tab applies to every table unless a table has its own engine set, so check the log to confirm every table uses **bayesian_network**. To learn how the tables relate, the platform copies some of the parent table's columns into each child table before training. They appear in the log with names beginning `__cond__`, for example `__cond__268335_CUSTOMER__credit_score` in `LOAN_ACCOUNT`. Numeric parent columns are grouped into ranges first (`BIN_0`, `BIN_1` and so on). #### Correlations: keep only a few per table A **correlation** tells the engine to look at a value in the parent table when it creates a child row. For example, "when you create a loan, look at the customer's credit score". Correlations are set on the definition, in the **Data Dictionary**, not in the training rule set. Every training run on that definition uses the correlations that are switched on there, so check them before you train. Each active correlation adds its parent column to the child table as an extra input, called a *conditioning column*. **Keep correlations selective.** When you run Analyze, at most 2 correlations per table are switched on by default: the 2 with the highest strength. The others are created but left switched off. You can switch more on yourself, but a few strong correlations work better than many. They keep training light, and give the engine enough rows to learn each pattern well. The engine groups the real rows by every combination of parent values and learns each group. The number of groups multiplies with every conditioning column: `N` columns with `k` values each gives `k^N` groups, but the number of training rows stays the same. With a few strong columns, each group has plenty of rows to learn from. In the example, two conditioning columns on `ACCOUNT_BEHAVIOUR`, such as `status_cd` and `principal_amt`, give about 20 groups of roughly 1,000 rows each. When you choose which correlations to keep: - **Keep the strongest.** They capture the real structure in your data. - **Count parent columns, not correlations.** Two correlations from the same parent column add only one conditioning column. - **Switch off correlations whose parent column is inactive** in the training rule set. They add nothing. - **Drop duplicates** that carry the same information. In the example, `default_flag` and `status_cd` had identical strengths, because `status_cd` already has a `DEFAULT` value. When you generate related tables, switch on **Use Sequential ID** for each table's primary key. Every key is then unique, every child row links to a parent row, and each parent has a similar number of children to the source. See [Generate data](/docs/bayesian-training-guide#generate-data). ### CPU vs GPU bayesian_network doesn't use a GPU, and runs well on CPU. If the log includes `CUDA libraries not found`, you're on CPU. This makes no difference to bayesian_network. ### Do I need a target column? No. A Bayesian network learns how all the columns relate to each other, so no single column is treated as the answer. --- ## 3. Hyperparameters A **hyperparameter** is a setting you choose before training. It controls *how* the model learns, as opposed to what it learns from the data. Changing a hyperparameter means you need to retrain. ### Activity settings These two settings are on the Configuration tab and apply to the whole activity, whichever engine you use. **Find Rules.** Searches for mathematical formulas linking your columns, such as one column being another divided by a third. It adds significant time to training. Leave it off for a first run, and turn it on later if you suspect columns are calculated from each other. **Imputation Strategy.** Decides how missing values are filled before training. | Option | How it fills a gap | Use for | | --- | --- | --- | | **Random Sample** | A value drawn from the column's existing values | Any column. Recommended default | | Mode | The most common value | Categories | | Least Frequent | The least common value | Rarely useful | | Mean | The average | Numbers only | | Median | The middle value | Numbers only | | Zero | 0 | Numbers where missing genuinely means zero | Random Sample keeps each column's proportions closest to the real data. Whichever option you choose, the model also records which values were originally missing, in an extra column called `<column>__missing_indicator`. This lets it learn the pattern of what's missing as well as the values. ### bayesian_network parameters **Structure learning** | Parameter | Example value | What it does | | --- | --- | --- | | `struct_learning_search_method` | `tree_search` | How the engine searches for the structure. See [Search methods](/docs/bayesian-training-guide#search-methods) | | `struct_learning_score` | `bic` | How a candidate structure is scored. `bic` favours simpler structures with fewer links. `k2` doesn't penalise extra links, so it can build a larger structure. Only used by search methods that allow several dependencies per column | | `struct_max_indegree` | 4 | The most columns any one column can depend on. Only used by search methods that allow several dependencies per column | | `struct_learning_n_iter` | 1000 | The most search steps allowed. Only used by search methods that allow several dependencies per column | **Data encoding and generation** | Parameter | Example value | What it does | | --- | --- | --- | | `encoder_max_clusters` | 10 | Maximum number of clusters used when encoding numeric columns. Higher values keep finer detail in numeric columns. Lower values make training lighter and faster | | `encoder_noise_scale` | 0.1 | How much random variation is added to generated numeric values. At 0, generated values repeat the exact values from the source. Higher values add more variety, but drift further from the real values | | `compress_dataset` | Off | Reduces the data before training. Leave off, so the output can be compared with the source | | `sampling_patience` | 500 | Number of attempts the engine makes to produce a valid row before giving up. Only matters if generation returns fewer rows than you asked for | ### Search methods The search method decides how the engine finds which columns depend on which. Each method suits a different kind of data, so the best choice depends on your table. | Method | How it works | Suits data where | Trade-offs | | --- | --- | --- | --- | | `tree_search` | Links every column into a tree. Each column depends on at most one other column | Columns have many distinct values, such as detailed numbers, or the row count is modest | Fast. Every column is linked, but each column depends on only one other. Ignores `struct_learning_score`, `struct_max_indegree` and `struct_learning_n_iter` | | `mmhc` | Runs a statistical test on each pair of columns to find which are related, then builds a structure where a column can depend on several others | Most columns are categories, codes, flags or bands with a small number of values each, there are many rows, and real patterns involve several columns together | Can capture patterns across several columns, and leaves unrelated columns unlinked. Needs enough rows for each combination of values to find a relationship | | `hillclimb` | Starts with no links, then repeatedly makes the single change that most improves the score. A column can depend on several others | Most columns are categories, codes or bands, and there are plenty of rows | Can capture patterns across several columns. Uses `struct_learning_score`, `struct_max_indegree` and `struct_learning_n_iter`. Can stop at a good structure rather than the best one | | `pc` | Uses statistical tests on groups of columns to decide which are linked. A column can depend on several others | Mostly categories and many rows, or a single table where numeric relationships matter | Can capture patterns across several columns. Needs enough rows for each combination of values to find a relationship | | `exhaustive` | Scores every possible structure and keeps the best | Tables with very few columns | Finds the best-scoring structure. The number of possible structures grows very quickly with each column, so it's suited to a handful of columns | **Search method and score combinations.** The score (`struct_learning_score`) only applies to methods that allow several dependencies per column. | Combination | Best for | What it means for your data | | --- | --- | --- | | `tree_search` | A single table with detailed numeric columns, or a quick first result | Every column is linked to one other, so relationships between pairs of columns are kept closely. Patterns that depend on several columns at once come out weaker | | `mmhc` + `bic` | Mostly categories, codes or bands, with many rows and patterns across several columns | Columns with no clear relationship are left unlinked. Needs enough rows for each combination of values; detailed numeric columns can leave too few, so fewer columns are linked | | `hillclimb` + `bic` | Mostly categories, codes or bands, including related tables | Builds a compact structure that keeps category proportions and links between categories. Relationships between detailed numeric columns are kept best when the numbers are grouped into bands | | `hillclimb` + `k2` | Smaller tables where you want the engine to find as many links as it can | Builds a larger structure with more links. Training takes longer and needs more resources, especially with columns that have many distinct values | | `pc` | Mostly categories with many rows, or a single table where relationships between numeric columns matter | Can keep patterns across several columns, including numeric relationships. Needs enough rows for each combination of values | | `exhaustive` | A handful of columns | Finds the best-scoring structure. Time grows very quickly with each extra column, so keep the column count small, for example by training only the columns you need | **Choosing for your own data.** Compare methods on your own table: 1. Look at your columns. Note how many distinct values each has, and whether important patterns involve more than two columns together. 2. Train with one method, generate, and compare the output with the source. See [Compare with the source](/docs/bayesian-training-guide#compare-with-the-source). 3. Retrain with another method, keeping every other setting the same, and set the same **Random seed** when you generate. 4. Compare the two outputs on the relationships and missing values you care about, and on training time. Methods that allow several dependencies per column, such as `hillclimb`, find more numeric relationships when detailed numbers are grouped into bands in the source. Raising `struct_max_indegree` and `struct_learning_n_iter` also lets them find more relationships. ### Example values The values used for the example table (around 12,000 rows, a mix of category and numeric columns). Use them as a starting point and adjust for your data. | Parameter | Value | Notes | | --- | --- | --- | | `struct_learning_search_method` | `tree_search` | The method used for the example. See [Search methods](/docs/bayesian-training-guide#search-methods) to choose for your data | | `struct_learning_score` | `bic` | Ignored by `tree_search`. Used by methods that allow several dependencies per column | | `struct_max_indegree` | 4 | Ignored by `tree_search` | | `struct_learning_n_iter` | 1000 | Ignored by `tree_search` | | `encoder_max_clusters` | 10 | Default | | `encoder_noise_scale` | 0.1 | Default | | `compress_dataset` | Off | Keeps the training data unchanged | | `sampling_patience` | 500 | Default | For related tables, lower values such as `struct_max_indegree` 2 and `encoder_max_clusters` 5 keep training lighter. ### Tuning: which setting to change Change one setting at a time and compare each run against the source. | What you see in the output | Try | | --- | --- | | Most relationships are missing: the correlation heatmap is almost blank | Check the method in the log and try another. If the method allows several dependencies per column, try raising `struct_max_indegree` and `struct_learning_n_iter`, or group detailed numbers into bands. See [Search methods](/docs/bayesian-training-guide#search-methods) | | Missing values appear about twice as often as in the source | The model hasn't linked the column to its missing-value indicator. Try another search method | | A pattern that depends on several columns is weaker than in the source | With `tree_search`, each column depends on only one other. Try `hillclimb` or `pc`, or apply it with a post-processing rule | | Generated numbers repeat the source's exact values too closely | Increase `encoder_noise_scale` slightly | | Generated numbers drift too far from realistic values | Lower `encoder_noise_scale` | | Generation returns fewer rows than you asked for | Increase `sampling_patience` | | Training is slow | Lower `encoder_max_clusters` or `struct_max_indegree`, group detailed numbers into bands, train fewer tables together, or try another search method | --- ## 4. Model ### What a trained model is A trained model is the result of a training job, attached to your data activity. It contains everything the engine learned from your data. It takes a snapshot of the training rule set when the job starts, so changes you make to the rule set afterwards don't affect a model that's already trained. You use the model by selecting it in a generation rule set (see [6. Generate and Validate](/docs/bayesian-training-guide#6-generate-and-validate)). Each new training run attaches its model to the activity in place of the previous one. Before you generate, check that the activity and the generation rule set point at the model you want. ### Output files When training finishes, open the trained model from the training rule set. The trained model page shows: - **Configuration files:** `training.json` and `metadata.json`, which you can download. - **Location:** the folder on your host server where the model files are saved. - **Engine parameters:** the engine settings the model was trained with, including the search method. `metadata.json` is the most useful configuration file: it shows the query used to load the training data, so you can confirm which columns were trained. See [Training output files](/kb/docs/machine-learning-extras#training-output-files) for what each file contains. ### Reading the training log Open the job log shortly after training starts and check these lines. **Engine and parameters:** ```plaintext Fit internal model 'bayesian_network' for table '