On 26 November 2026 at 09:33:43-09:34:17 Asia/Shanghai, the official FreqAI Configuration page (HTTP 200) required classifier targets to be discrete strings and required class_names to be declared in set_freqai_targets. The fetched stable BasePyTorchClassifier.py (HTTP 200, SHA-256 4186015da616ddfeb675f67eef66e2a7983f171ead87dcdea1c8fce837edfcef, commit 649af43f0c581b0101d88f0d8351690d035aedb0 from the public commits API) raises on empty declared names and raises Found non defined labels when target-column values are not in class_names. A labelled up/down/flat mismatch is walked through as a hypothetical. No model was trained.

Documentation review. AI-assisted drafting. Educational information; no individual financial advice.

The PyTorch classifier label-vocabulary contract, not a training log

The assigned question is how FreqAI's PyTorch classifier checks string targets against declared class_names, and what the "Found non defined labels" guard is doing. Official FreqAI Configuration was re-read at 09:33:43 Asia/Shanghai on 26 November 2026 (HTTP 200; Last-Modified: Wed, 25 Nov 2026 09:26:47 GMT). The same morning, the project's stable-branch documentation source `docs/freqai-configuration.md` returned HTTP 200 at 09:33:44 Asia/Shanghai and is used as a text twin; citations still use the canonical Configuration URL. The PyTorch base classifier on the stable branch, `BasePyTorchClassifier.py`, was fetched at 09:33:43 Asia/Shanghai (HTTP 200). That file's SHA-256 is 4186015da616ddfeb675f67eef66e2a7983f171ead87dcdea1c8fce837edfcef, which matches the 24 November 2026 pantry snapshot. Raw GitHub response headers on this fetch exposed an ETag, not a git commit. The public GitHub commits API for that path on stable returned commit 649af43f0c581b0101d88f0d8351690d035aedb0 at 09:34:17 Asia/Shanghai (HTTP 200; commit time 2026-08-05T18:35:33Z, or 02:35:33 Asia/Shanghai on 6 August 2026). The stable branch remains mutable; the quotes below are from this snapshot. This draft does not train a model, does not run a classifier, and does not claim that a local fix was verified. The up/down/flat example later in the article is a labelled hypothetical.

The scope is the fetched BasePyTorchClassifier source and the official Configuration page. This article does not extend the same guard to every FreqAI model, including other classifier families named on that page.

Official classifier targets are discrete strings

The Configuration page distinguishes regression from classification: a classifier "will predict a target of discrete values." In the "Classifiers" section, official text says that if you use a classifier, "the classes need to be set using strings." The worked example writes 'up' or 'down' into a target column named &s-up_or_down, using a comparison of close against a 100-candle shift. That section also shows how to add a third label in the same column: 'same', for an unchanged price. The official typo "If you elects to use a classifier" is left as written on this morning's fetch.

A later Configuration note, "Setting Class Names for Classifiers," is more specific about declaration. "When using classifiers, the user must declare the class names (or targets) by overriding the IFreqaiModel.class_names attribute." The documented method is to set self.freqai.class_names inside set_freqai_targets. The official binary example sets self.freqai.class_names = ["down", "up"] and then writes the 'up' / 'down' strings into &s-up_or_down. Those two lists are the vocabulary contract: the declared names, and the actual strings stored in the target column.

This is an output-label question, not an input-feature question. It is not a "Could not find any features" prefix check, and it is not a feature-expansion count.

What the fetched PyTorch base code checks

In the fetched BasePyTorchClassifier.py, get_class_names() raises a ValueError when self.class_names is empty. The message tells the reader to set self.freqai.class_names = ['class a', 'class b', 'class c'] inside IStrategy.set_freqai_targets. That is a missing-declaration guard. It is not the "Found non defined labels" error.

The "Found non defined labels" wording lives in assert_valid_class_names. That static method takes the target column and the declared class_names list, then computes non_defined_labels = set(target_column) - set(class_names). If that set is not empty, it raises OperationalException with a first argument that begins Found non defined labels: {non_defined_labels}, and a second argument expecting labels: {class_names}. This draft quotes those two arguments as they appear in the fetched file. It does not execute the exception class, and it does not invent a runtime traceback.

encode_class_names calls that assertion on the target column of each split in self.splits before it maps each label string through class_name_to_index. The comparison is an exact set difference of values present in the column versus names present in the declared list.

Two consequences follow from the fetched comparison and should stay labelled as code readings, not as test logs. First, a string that appears in the column but is absent from class_names is an extra, and extras are what this guard reports. Second, a name that is declared but never appears in the column is not, under this subtraction, a member of non_defined_labels. Official docs on this morning's Configuration fetch do not discuss that second case, and this article does not invent a second official error message for it.

A labelled hypothetical: up, down, and flat

The walkthrough below is hypothetical. No dataframe was built, and no trainer was started.

Suppose a strategy follows the official binary declaration, self.freqai.class_names = ["down", "up"], but the target column &s-up_or_down also contains the string 'flat' for some rows (for example, a third branch written for an unchanged or small move). Under the fetched set difference, set(target_column) - set(["down", "up"]) includes 'flat'. The official guard is written to treat that leftover set as non_defined_labels and to raise OperationalException using the "Found non defined labels" wording cited above.

The official Configuration example uses 'same', not 'flat', when it adds a third class for an unchanged price. The mismatch is the same kind of leftover if 'same' is written into the column and omitted from class_names. Exact spelling matters in the fetched comparison: 'Up' is not the same string as 'up'. Those variants are listed so the contract is visible. They are not observed rows from a run, and they are not a claim that any one third label is a good trading target.

A matching vocabulary, still hypothetical, would declare every string that the target column can actually take, for example ["down", "up", "flat"] when those three strings are the ones being written. This article does not prescribe that list, assign class profitability, or treat a matching declaration as a verified fix. Empty class_names would still be a different failure, the ValueError from get_class_names.

Method and limits

Sources are the official Configuration page and the fetched BasePyTorchClassifier.py snapshot dated 26 November 2026, with the commit SHA obtained from the public commits API as noted above. No FreqAI or PyTorch training run was started. Error semantics are scoped to that PyTorch base class. Other official classifier flags, such as LightGBMClassifier on the same Configuration page, were not fetched as source files and are not assumed to share this guard. The stable branch can move; anyone repeating the reading should hash the file again.

TradeBotBench carries exchange affiliate links elsewhere; this post contains none. This article makes no performance claims about FreqAI models or any trading results.

Related pages already on this site cover adjacent problems without answering this label-vocabulary question: the FreqAI `do_predict` and DI log check, the download-data timerange and startup candles article, the guide to evaluating a trading bot, and the backtest statistics tool.

Sources & method

What this article adds

A dated reading of official FreqAI Configuration and of fetched BasePyTorchClassifier.py as they stood at 09:33:43-09:34:17 Asia/Shanghai on 26 November 2026: discrete string classifier targets, the class_names declaration, the empty-name ValueError, and the Found non defined labels set-difference guard, plus a labelled hypothetical up/down/flat mismatch. The snapshot hash and commit SHA are recorded. No training run was performed and no fix was verified.

How it was prepared

The official Configuration HTML page was fetched with curl at 09:33:43 Asia/Shanghai on 26 November 2026 (HTTP 200, Last-Modified Wed, 25 Nov 2026 09:26:47 GMT). The official stable-branch docs/freqai-configuration.md text twin was fetched at 09:33:44 (HTTP 200). BasePyTorchClassifier.py was fetched from the stable branch at 09:33:43 (HTTP 200, SHA-256 4186015da616ddfeb675f67eef66e2a7983f171ead87dcdea1c8fce837edfcef, identical to the 24 November pantry snapshot). Raw response headers did not expose a git commit; the public GitHub commits API for that path on stable was queried at 09:34:17 (HTTP 200) and returned 649af43f0c581b0101d88f0d8351690d035aedb0. No FreqAI or PyTorch training run was started.

String and discrete classifier-target rules, the official up/down and same examples, and the class_names declaration come from the official FreqAI Configuration page fetched 26 November 2026. The empty class_names ValueError, the set-difference comparison, and the Found non defined labels wording come from the fetched stable BasePyTorchClassifier.py snapshot the same morning. The commit SHA comes from the public commits API, not from raw.githubusercontent.com headers.

For corrections, contact the publisher. Editorial policy · Affiliate disclosure

Put it into practice