ganfs Open-Sourced: Letting GANs Select Features

The Python tool ganfs was recently open-sourced. It ranks features in high-dimensional data by perturbing a GAN discriminator. The approach can capture nonlinear relationships, but “hard to fake” does not necessarily mean “most useful for prediction.”
GANs Are No Longer Just Generating Images—They’re Starting to Select Features for Data Scientists
A Python tool called ganfs (Generative Adversarial Network Feature Selection) was recently open-sourced. It applies generative adversarial networks to automatic feature selection in high-dimensional data: first, it trains a GAN to learn the data distribution; then, it perturbs input features one by one and observes the discriminator’s response to determine which features are more important.
This is not another project that simply wraps SelectKBest in a large language model. The core idea behind ganfs is: if modifying a feature makes it easier for the discriminator to detect that something is “off” about a sample, then that feature is harder to fake and more representative of the original data distribution.
The idea is intuitive and appealing. When dealing with data containing hundreds, thousands, or even more dimensions, developers can obtain a feature ranking without first writing a set of domain-specific rules. Sensor data, gene expression, network traffic, and financial risk variables are all potential use cases.
But expectations need to be set appropriately: ganfs addresses the question of “which variables are most important for preserving the data distribution,” which is not necessarily equivalent to “which variables best predict your business label.” The former is closer to unsupervised representation learning, while the latter is a supervised learning objective. The two often overlap, but they are by no means the same thing.

How It Determines Whether a Feature Is “Hard to Fake”
A traditional GAN consists of a generator and a discriminator. The generator tries to produce convincing samples, while the discriminator distinguishes real data from generated data. Through adversarial training, the generator gradually approximates the real data distribution, while the discriminator learns to focus on the most distinctive structures in real samples.
ganfs makes use of the latter.
After training is complete, it perturbs one feature dimension—for example, by permutation, masking, replacement, or adding noise—and then compares the discriminator’s outputs before and after the perturbation. If changing a single column causes a large shift in the discrimination result, that column is important to the discriminator’s understanding of the real distribution. If modifying it has little effect, the column may contain limited information, or its information may already be captured by other features.
In conceptual pseudocode, the process looks roughly like this:
Input: training data X with d features
Training: train generator G and discriminator D on X
baseline = D(X)
for j in 1...d:
X_perturbed = perturb the j-th feature of X
changed = D(X_perturbed)
score[j] = aggregate(|baseline - changed|)
Sort by score in descending order
Output: feature ranking or Top-K feature subset
This process is not the official ganfs API; it is included only to explain the algorithmic idea. The project’s public announcement emphasizes “perturbing the discriminator and analyzing its response,” but details such as the perturbation strategy, aggregation function, training stopping criteria, and software interface should be verified against the project’s actual code and future documentation.
“Hard to fake” can be understood by analogy with a counterfeit detector examining banknotes. If altering the watermark immediately triggers an alert, the watermark is clearly a key feature. If changing an ordinary background pattern produces no response, that pattern has relatively little discriminative value. In high-dimensional tabular data, however, the “watermark” is often not a single isolated column, but a nonlinear relationship formed jointly by multiple variables.
That is precisely what makes the GAN-based approach more interesting than a simple correlation coefficient.
What Gap Is It Really Trying to Fill Compared With Traditional Methods?
Feature selection methods generally fall into three categories:
- Filter methods: Directly screen features using metrics such as correlation coefficients, chi-squared tests, and mutual information. They are fast, but often score individual features separately and may miss complex interactions.
- Wrapper methods: Repeatedly train a downstream model and compare the performance of different feature subsets. They have a clear objective, but searching through feature combinations is computationally expensive.
- Embedded methods: Perform selection during the training of models such as L1-regularized models, decision trees, or gradient-boosted trees. They offer a relatively good balance between efficiency and effectiveness, but the results depend on the specific model and labels.
By comparison, ganfs is closer to an unsupervised selection method based on generative modeling and perturbation analysis. Instead of looking only at the linear relationship between a column and a label, it attempts to learn the entire joint distribution.
Suppose a dataset contains two variables that individually have little relationship with the outcome but jointly form a clear decision boundary. A correlation coefficient may rank both near the bottom, while a neural network discriminator may be able to capture their interaction. This approach has practical value for data containing many nonlinear dependencies.
| Method | Requires labels | Nonlinear capability | Computational cost | Main risk | |---|---:|---:|---:|---| | Correlation coefficients, chi-squared tests | Depends on the method | Weak | Low | Missing interactions | | Mutual information | Optional | Moderate | Low to moderate | Unstable estimation in high dimensions | | L1 regularization | Yes | Depends on the model | Moderate | Biased toward a specific predictive model | | Tree-based feature importance | Yes | Strong | Moderate | Bias toward high-cardinality and correlated variables | | Wrapper search | Yes | Depends on the downstream model | High | Combinatorial explosion | | ganfs | Can operate without labels | Strong | Moderate-high to high | Instability in GAN training and perturbation definitions |
Therefore, the most noteworthy aspect of ganfs is not the word “automatic.” Many mature tools for automatic feature selection already exist. Its distinguishing feature is that it uses the discriminator’s sensitivity to the data distribution instead of manual rules or a single statistical metric.
“No Domain Expert Required” Is Both a Selling Point and the Claim That Deserves the Most Caution
The project’s author emphasizes that important variables can be identified without manual input from domain experts. This is indeed useful during early exploration, but problems can arise if it is interpreted as a way to bypass business knowledge altogether.
The first issue is that the features the discriminator focuses on may not have business value.
For example, in medical data, hospital IDs, device models, or collection batches may be highly distinguishable, and a GAN may treat them as “hard-to-fake” structures. But these variables may merely reflect the data source and may even constitute leakage. They may be important for reproducing the current data distribution while harming generalization across hospitals.
The second issue is that distributional importance is not the same as label-prediction capability.
Suppose a credit-risk dataset includes the user’s city. The city variable may significantly shape the overall data distribution, making the discriminator highly sensitive to it. But income volatility and debt ratio may be the variables that actually predict default. If the selection objective is to improve classifier AUC, the selected features still need to be validated on the downstream task.
The third issue is that correlated features may substitute for one another.
When two variables are highly correlated, perturbing only one may allow the discriminator to recover the information from the other, causing both variables to receive low individual scores. This does not mean they have no value; rather, single-variable perturbation may not correctly measure redundant feature groups. A more mature implementation needs to consider grouped perturbation, conditional perturbation, or at least provide correlation diagnostics.
A more accurate claim, therefore, would be that ganfs can reduce reliance on manual expertise during the initial search, but it cannot replace data auditing, causal reasoning, and business acceptance testing.
Using GANs on High-Dimensional Data May Not Be Cheaper Than Traditional Methods
The project targets high-dimensional data, but being “suitable for high dimensions” is not merely a matter of whether the algorithm can accept thousands of input columns. It must also be able to train and rank features stably and economically.
If a complete perturbation evaluation is performed separately for every feature, the baseline cost grows approximately linearly with dimensionality. For a dataset with 10,000 columns, the evaluation workload is substantial even if the discriminator only performs forward inference. The implementation can reduce costs by constructing perturbed samples in batches, sampling a subset of the data, using gradient-based approximations, or applying hierarchical screening, but these optimizations may further affect ranking accuracy.
GANs themselves are not known for being easy to manage:
- Training instability. When the generator and discriminator become unbalanced, importance scores may reflect a boundary formed by chance during a particular training run.
- Mode collapse. If the generator covers only part of the data distribution, the discriminator may also focus on the wrong structures.
- Difficulty handling mixed data types. When continuous values, categorical values, missing values, and long-tailed variables are mixed together, preprocessing choices can significantly alter the results.
- High randomness. Different initializations, batch orders, and hyperparameters may produce different rankings.
- Perturbations may leave the real data distribution. Randomly shuffling age values may create samples inconsistent with education or years of employment. A strong discriminator response may sometimes occur simply because the perturbation created obvious anomalies, not because the feature is genuinely important.
This means that, compared with mutual information, L1 regularization, or tree-based feature importance, ganfs is not a cheaper or more stable replacement by default. It is better viewed as a new tool worth adding to comparative experiments, especially for complex joint distributions that traditional statistical methods struggle to describe.
How Developers Should Evaluate It Instead of Looking Only at a Ranking Table
For teams planning to try ganfs, the most important question is not whether it can output a Top-20 list, but whether those 20 features actually improve the target task.
A relatively reliable evaluation process includes the following:
1. Perform Selection Only on the Training Set
Do not train the GAN on the full dataset before splitting it into training and test sets. Even without using labels, the GAN has still seen the test-set distribution, which causes information leakage. The rigorous approach is to retrain the feature selector within each cross-validation fold.
2. Compare Against Simple Baselines
At minimum, include the following comparisons:
- Variance filtering and correlation filtering;
- Mutual information;
- L1-regularized models;
- Random forest or gradient-boosted tree importance;
- Randomly selecting the same number of features;
- A model using all features.
If ganfs requires dozens of times more computation but does not consistently outperform these baselines, it is not worth deploying on the current dataset.
3. Do Not Look Only at Accuracy
In addition to classification or regression metrics, record:
- Feature compression ratio;
- GAN training and ranking time;
- Peak GPU memory and system memory usage;
- Top-K overlap across different random seeds;
- Whether the ranking remains effective with a different downstream model;
- Whether retraining is required after data drift.
Among these, ranking stability is especially important. If one experiment selects A, B, and C, but changing the random seed yields X, Y, and Z, the ranking will be difficult to use for scientific interpretation or production decisions.
4. Validate “Distribution Preservation” Separately From “Label Prediction”
If the goal is unsupervised compression, evaluate whether the selected features preserve clustering structure, anomaly-detection performance, or distributional distance. If the goal is classification or regression, directly compare downstream task metrics. Do not use results for one objective to justify claims about the other.
Better Suited to Exploration Than Direct Control of Production Feature Governance
Methodologically, ganfs offers a reasonable and distinctive direction: using a GAN discriminator as a “stress sensor” for high-dimensional data and identifying the key variables that preserve the joint distribution through perturbation. Compared with simple univariate filters, it has a better chance of discovering nonlinear structures, and it is easier to scale than exhaustive feature-subset search.
At present, however, it is more of a research tool and experimental component than an industrial-grade module that can unconditionally replace existing pipelines. The randomness of GANs, the difficulty of modeling tabular data, the choice of perturbation method, and the mismatch between unsupervised importance and business objectives all require independent validation by developers.
In particular, the claim that “no domain expert is required” should be understood as lowering the barrier to entry, not eliminating the need for expert review. The challenge of feature selection has never been limited to calculating a score. It also includes identifying leakage, bias, proxy variables, compliance risks, and causal direction—issues for which the discriminator will not proactively take responsibility on behalf of the team.
As of July 30, 2026, the open-sourcing of ganfs has at least added another experimental approach to high-dimensional feature selection. It is useful, but it is better placed in a benchmark alongside mutual information, L1 regularization, tree-based models, and downstream tasks than moved directly into production merely because it uses a “GAN.”
References
- Reddit: Announcement post by the ganfs project author: The author introduces the motivation behind the open-source Python package, its GAN training process, and the basic idea of ranking features by perturbing inputs and analyzing the discriminator’s response.
- Zhihu: Generative Modeling: GANs (High-Resolution Generation): Provides additional background on GAN generators, discriminators, and adversarial training; it is not official ganfs implementation documentation.



