The Quantum Distance-based classifier is a technique inspired by the classical k-Nearest Neighbors that leverage quantum properties to perform prediction. The package has been implemented in Qiskit
Project description
The Quantum Distance-based classifier is a technique inspired by the classical k-Nearest Neighbors that leverage quantum properties to perform prediction. The package has been implemented in Qiskit.
```
from quantum_distance_based_classifier.quantum_distance_based_classifier import QuantumDistaceBasedClassifier
from sklearn import preprocessing
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
import numpy as np
X, y = load_iris(return_X_y=True)
n_features = 2
X = X[:, :n_features] # Keep only n_features
# Standardize and normalize the features
X = StandardScaler().fit_transform(X)
X = preprocessing.normalize(X, axis=1)
# Initialize variables to store sampled instances
sampled_X = []
sampled_y = []
# Loop through each class to sample instances
for class_label in np.unique(y):
class_indices = np.where(y == class_label)[0]
sampled_indices = np.random.choice(class_indices, size=instances_per_class, replace=False)
sampled_X.extend(X[sampled_indices])
sampled_y.extend(y[sampled_indices])
# Convert lists to numpy arrays
sampled_X = np.array(sampled_X)
sampled_y = np.array(sampled_y)
qdbc = QuantumDistaceBasedClassifier()
qdbc.fit(sampled_X, sampled_y)
result = qdbc.predict(sampled_X[0])
print(f"Classification result: {result}")
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file quantum_distance_based_classifier-0.0.4.tar.gz.
File metadata
- Download URL: quantum_distance_based_classifier-0.0.4.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd5059d37b5e11bc9d976fa166b43aa7bafed55b98d8a4512758114e599c48cc
|
|
| MD5 |
942328a217922bab61424b4bdc6c500f
|
|
| BLAKE2b-256 |
5cc1427c66ac4f721ead879ab06d9ebde30d8a345198af31364724aef00b4e1a
|