Quantum Regression#
This tutorial demonstrates regression with VQCRegressor.
Setup#
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from psipose.estimators import VQCRegressor
Generate Data#
np.random.seed(42)
X = np.sort(5 * np.random.rand(100, 1), axis=0)
y = np.sin(X).ravel() + np.random.normal(0, 0.1, X.shape[0])
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=42
)
Train Regressor#
reg = VQCRegressor(n_qubits=3, n_iter=100, random_state=42)
reg.fit(X_train, y_train)
Evaluate#
y_pred = reg.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print(f"MSE: {mse:.4f}")