Package: seleqt
seleqt- Quantum Feature SelectionThis package contains a minimal implementation of the Quantum Feature Selection (QFS) algorithm described inMücke et al., 2023.
Given a labeled dataset, this package provides methods todiscretize the datacompute redundancy and importance values based on mutual informationgenerate feature selection QUBO instances for a given αfind an α such that a FS QUBO has exactly k bits in its minimizing binary vectorInstallationThis package can be installed directly viapipfrom the PyPi repository:pip3 install seleqtUsageData and labels must be given asnumpyarrays:
The dataxmust have shape(n, d), wherenis the number of samples/observations anddis the number of features.
The labelsymust have shape(n,).
Bothxandymust bediscrete, i.e., their type must be a subtype of integer.
Optimally, their values should correspond to indices (0,1,...,B-1) of a finite number of binsB.fromseleqtimport*DiscretizingThis package provides a methoddiscretizethat takes real-valued data and discretizes it by computing bins and returning the corresponding bin indices.
Its parameters arex: Input databins: Number of bins (default 10)method: Method to compute bin edges, must be either"equal"or"quantile".
For"equal", the value range is divided intobinsequally sized bins.
For"quantile", the b/bins-quantiles for b in 0,...,binsare computed and used as bin edges. Default is"equal".share_bins: Boolean that indicates if the bins should be computed over all values together vs. all columns separately. Default isTrue.x_=discretize(x,bins=20,method='quantile')Redundancy and ImportanceThe methodsredundancy()andimportance()compute what their names suggest.
As inputs,redundancy()expects justx, andimportance()expects bothxandy.
All inputs must be discrete.
The result ofredundancy()is anumpyarray of shape(d, d), andimportance()returns a shape(d,)array.red=redundancy(x_)imp=importance(x_,y)Create QUBO InstanceGiven redundancy and importance, the methodfeature_selection_qubo()creates a QUBO parameter matrix according to Eq. 18 in the paper.
It takes the following arguments:redundancy:numpy.ndarrayof shape(d, d)containing pairwise redundancy between the featuresimportance:numpy.ndarrayof shape(d,)containing importance for each featurealpha: float between 0 and 1; weighting of importance against redundancy. Corresponds to α in Eq. 18.importance_threshold: non-negative float; minimal meaningful importance value. Corresponds to ε in Eq. 18.threshold_penalty: non-negative float; penalty value swapped in for importance when it is belowimportance_threshold. Corresponds to μ in Eq. 18. Default is theThe return value is anumpy.ndarrayof shape(d, d)containing the QUBO parameters as an upper-triangular matrix.Q=feature_selection_qubo(red,imp,alpha=0.7)Perform QFS AlgorithmTo perform Alg. 1 from the paper, you can useqfs(), which takes the following arguments:redundancyandimportance: Same as forfeature_selection_qubo()k: int, with 0 <k<d; target number of features to select.importance_thresholdandthreshold_penalty: Same as forfeature_selection_qubo()precision_limit: non-negative float; smallest allowed search interval for binary search. Default is1e-8.qubo_solver: Callable function that takes a(d, d)QUBO parameter matrix and outputs a binary vectorxthat minimizesx @ Q @ x.
Corresponds to the QUBO oracle used in Alg. 1.The result in a tuple(alpha, min_x)containing the optimal α value and the minimizing binary vector, which haskones.The following example uses the light-weight packagequboliteto implement the QUBO oracle.
Note that the brute-force solver is only feasible for dimensions up to about 30.fromquboliteimportqubofromqubolite.solvingimportbrute_forcedefbrute_force_solver(q):returnbrute_force(qubo(q))alpha,min_x=qfs(red,imp,5,qubo_solver=brute_force_solver)CitationIf you use this package in your scientific work, please cite the following article:Mücke, S., Heese, R., Müller, S. et al. Feature selection on quantum computers. Quantum Mach. Intell. 5, 11 (2023). https://doi.org/10.1007/s42484-023-00099-zBibtex:@article{muecke2023,
    title={Feature selection on quantum computers},
    author={M{\"u}cke, Sascha and Heese, Raoul and M{\"u}ller, Sabine and Wolter, Moritz and Piatkowski, Nico},
    journal={Quantum Machine Intelligence},
    volume={5},
    number={1},
    pages={11},
    year={2023},
    publisher={Springer},
    doi={10.1007/s42484-023-00099-z}
}