mantispy.pp.feature_select#
- mantispy.pp.feature_select(adata, operations=('variance_threshold', 'correlation_threshold', 'drop_na_columns', 'blocklist'), min_variance=1e-06, freq_cut=0.05, unique_cut=0.01, corr_threshold=0.9, corr_method='pearson', na_cutoff=0.05, outlier_cutoff=500.0, blocklist='default', noise_removal_perturb_groups='Metadata_Perturbation', noise_removal_stdev_cutoff=0.8, key_added='selected', copy=False)#
Flag the features worth keeping.
- Parameters:
adata (
AnnData) – Object to select features on. Usually well-level profiles.operations (
Sequence[str] (default:('variance_threshold', 'correlation_threshold', 'drop_na_columns', 'blocklist'))) – Which operations to run, fromOPERATIONS. The default omitsfrequency_threshold,drop_outliersandnoise_removal, matching pycytominer’s own default.min_variance (
float(default:1e-06)) –variance_threshold: keep features with variance above this.freq_cut (
float(default:0.05)) –frequency_threshold: drop a feature when the count of its second most common value divided by the count of its most common is below this. Either this rule orunique_cutdrops a feature.unique_cut (
float(default:0.01)) –frequency_threshold: drop a feature when its share of distinct values is below this.corr_threshold (
float(default:0.9)) –correlation_threshold: drop one member of every pair correlated above this.corr_method (
str(default:'pearson')) –correlation_threshold:"pearson"or"spearman".na_cutoff (
float(default:0.05)) –drop_na_columns: drop features missing in more than this fraction of rows.outlier_cutoff (
float(default:500.0)) –drop_outliers: drop features whose absolute value exceeds this.blocklist (
str|Sequence[str] (default:'default')) –blocklist:"default"for the bundled list, or explicit names. Matched against the current names and againstvar["original_name"], so it works either side ofstandardize_feature_names().noise_removal_perturb_groups (
str(default:'Metadata_Perturbation')) –noise_removal:obscolumn grouping replicates.noise_removal_stdev_cutoff (
float(default:0.8)) –noise_removal: drop features whose within-group standard deviation, averaged over groups, is above this.key_added (
str(default:'selected')) – Name of the booleanvarcolumn to write.copy (
bool(default:False)) – Return a modified copy instead of mutating in place.
- Return type:
- Returns:
None, or the modified copy. Writesvar[key_added]and a per-operation count of removals touns["mantispy"]["feature_select"], each count being what that operation removes on its own. Nothing is dropped; usesubset_features()for that.- Raises:
ValueError – If
operationsnames an operation that is not inOPERATIONS.KeyError – If
noise_removalis requested butnoise_removal_perturb_groupsis not anobscolumn.
Notes
Every operation judges the full feature set, so each count in
uns["mantispy"]["feature_select"]says what that operation alone would remove and is the same whatever orderoperationsruns in. The counts therefore overlap: a feature that is both constant and mostly missing is counted byvariance_thresholdand bydrop_na_columns, and the counts sum to more than the number of features actually removed, which isn_varsminusvar[key_added].sum().correlation_thresholdis the most expensive operation. pycytominer usespandas.DataFrame.corr, one Cython pass per column pair. Here the pairs come from chunked matrix products over blocks of columns, so non_vars ** 2array is held in memory.