Designing a Fair Comparison of Logistic Regression and Tree Models
Part 7 designed labels and training timing for logistic regression. This article asks what must stay fixed when decision trees and random forests receive the same inputs. It does not rank models trained on actual ETF data.
If features, periods, and costs change along with the model, it becomes difficult to identify the source of any difference. Fix shared conditions first and record model-specific choices separately.
The roles of four comparison groups
| Group | Inputs and signal | What to examine |
|---|---|---|
| 12-month momentum | A predefined price rule | A baseline without ML |
| Logistic regression | Positive-class scores from shared features | A simple classification baseline |
| Decision tree | Successive splits on features and thresholds | The effect of adding nonlinear conditions |
| Random forest | Combined predictions from multiple trees | Whether stability differs from a single tree |
A tree can express combinations such as “recent returns are positive and volatility is low.” That capability alone does not improve predictions. Without limits on depth and leaf size, a tree has more room to fit the training sample's details. Decision tree API
Random forests combine multiple trees. Whether this structure is superior in this ETF comparison requires a separate run. Do not replace future-period evaluation with an OOB score alone; apply the same chronological evaluation to every model. Random forest API
Check the input table first
Each row represents one ETF on one signal date.
| Column | Meaning | Needed for current prediction? |
|---|---|---|
symbol | Asset identifier | Yes |
signal_date | Date on which features are used to make a decision | Yes |
| Feature columns | Historical returns, volatility, and other values available at signal time | Yes |
label_end_date | Date on which the next holding-period outcome becomes known | For training eligibility |
label | 1 for a known positive return, otherwise 0 | Only for training and later evaluation |
A missing label on a current prediction row is normal. Do not mix future labels or the future prices used to calculate them into features. Assets sharing a signal date belong in the same time partition.
The code below selects data for one signal date from an already prepared samples table. It illustrates shared input conditions, not a complete model-training runner.
def window_at(samples, signal_date, features): train = samples.loc[ samples['signal_date'].lt(signal_date) & samples['label_end_date'].lt(signal_date) & samples['label'].notna() ].copy() current = samples.loc[samples['signal_date'].eq(signal_date)].copy() if current.empty: raise ValueError('예측할 자산 행이 없습니다') if set(train['label'].astype(int)) != {0, 1}: raise ValueError('공통 학습창에 클래스 0과 1이 필요합니다') return train[features], train['label'].astype(int), current[features]Missing or infinite features, duplicate rows, missing assets, and minimum training requirements must be checked outside this function. The date comparison conservatively excludes labels ending on the same date. To include same-day information, compare actual availability times with the training cutoff instead.
Only the model and predeclared candidates change
The three ML models receive the same features, labels, training rows, and prediction rows. Fit logistic regression's scaling only within the corresponding training window, then apply that transformation to prediction rows. Preprocessing and data leakage
A first comparison could keep the search small, for example as follows. These numbers are illustrative candidates to declare in advance, not recommended optima or validated settings.
| Model | Example candidates |
|---|---|
| Logistic regression | One combination: C=1.0, max_iter=2000 |
| Decision tree | Two combinations: (max_depth=3, min_samples_leaf=20) and (5, 40) |
| Random forest | One combination: n_estimators=300, max_depth=5, min_samples_leaf=20, max_features='sqrt' |
Record that the candidate counts differ. Before execution, check whether the example's large leaves are appropriate for the actual training sample, and do not silently add candidates after seeing validation results. Preserve seeds, library versions, convergence warnings, and actual run counts.
During validation, choose one setting per model using a predeclared criterion. Keep that setting during testing. Monthly retraining may add earlier observations whose outcomes are now known. Changing depth or features after seeing test performance constitutes a new experiment.
Do not turn an inability to train into a favorable result
If a month's training data contains only one class or required features are missing, the shared comparison conditions break. Training only the tree and dropping months where logistic regression failed produces different evaluation periods.
One proposed approach is to establish a common warm-up period and then fix the evaluation calendar. If a required check fails during evaluation, record the run as failed. Do not fill interrupted months with zero returns or pretend that all assets were held as cash. Cash is a valid outcome of a selection rule; a program failure is different.
Apply the same trading rule to probabilities
Select assets whose estimated class-1 probability is at least 0.50, assigning equal weights; hold cash if none qualify. Find the positive-class column through classes_. This threshold is a shared comparison assumption. Probability output API
Apply month-end signals at the next observed trading day's close, without assigning returns from the earlier holding period retroactively to the new signal. Recalculate momentum using the same evaluation calendar, assets, accounting, and costs. Do not compare a short ML evaluation directly with Part 6's full-period result.
Read the results in order
First check that prediction-row counts and evaluation dates match across models. Then inspect accuracy, positive prediction rates, and probability distributions. Finally compare after-cost returns, drawdowns, turnover, and cash allocation under the shared trading rule.
Higher accuracy can coincide with worse after-cost results if trading increases. Lower drawdown accompanied by much more cash requires distinguishing prediction improvement from reduced exposure. This is why comparison dates and failure records should be checked before declaring a winner.
The output of this article is a comparison specification, not a ranking. When actual results become available, connect selected settings, rejected candidates, and failed runs to the same record.
Report an error or share feedback
Open a draft with this article’s title and URL. Review the message and recipient before sending.
Open email draftIf no email app opens, copy these details into your usual email service.
Related posts
Quant & Data Research Designing a Logistic Regression Comparison: Timing, Evaluation, and Failure Handling
A design for comparing logistic regression with a baseline: timing, common evaluation periods, costs, and failure handling, distinguished from actual model results.
Quant & Data Research Why shift(1) Is Not Enough: A Time Contract for Signals, Execution, and Labels
Synthetic checks for signal timing, execution, return attribution, completed labels, and preprocessing, including deliberately faulty implementations.