paddle_quantum.data_analysis.vqr
The VQR model.
- paddle_quantum.data_analysis.vqr.load_dataset(data_file, model_name)
 Loading the Kaggle regression model
You may obtain a copy of the License at https://www.kaggle.com/code/alirfat/starter-fish-market-8f18fa38-4/data .
- Parameters:
 data_file (str) – Dataset file name.
model_name (str) – should be either
linearorpoly.
- Returns:
 Raw data.
- paddle_quantum.data_analysis.vqr.IPEstimator(circuit, input_state, measure_idx=[0])
 Kernel-1 using direct encoded data state to evaluate inner product
- class paddle_quantum.data_analysis.vqr.QRegressionModel(data_file, model_name, x_feature, y_feature, num_variable, init_params, num_qubits=6, learning_rate=0.1, iteration=100, language='CN')
 Bases:
objectRegression model covering all classes.
- Parameters:
 data_file (str) – The dataset.csv file.
model_name (str) – The regression model.
x_feature (List[str]) – Independent variables from data labels.
y_feature (str) – Dependent feature values.
num_variable (int) – The number of variable initialized in the model.
init_params (List[float]) – The initial parameters.
num_qubits (int) – The number of qubits in the estimator. Defaults to 6.
learning_rate (float) – The learning rate. Defaults to 0.1.
iteration (int) – The number optimization steps. Defaults to 100.
language (str) – The print language, Defaults to
CN.
- regression_analyse()
 
- class paddle_quantum.data_analysis.vqr.LinearRegression(num_qubits, num_x=1)
 Bases:
LayerRegression class for initializing a quantum linear regression model
- Parameters:
 num_qubits (int) – The number of qubits which the quantum circuit contains.
num_x (int) – The the number of independent variables of data. Defaults to
1.
- property reg_param: Tensor
 Flattened parameters in the Layer.
- set_params(new_params)
 set parameters of the model.
- Parameters:
 params – New parameters
- fit(X, y, learning_rate=0.01, iteration=200, saved_dir='', model_name='linear')
 Fitting method used for training the model
- Parameters:
 X (Tensor | ndarray) – Independent data in a 2D array.
y (Tensor | ndarray) – Dependent data in an 1D array.
learning_rate (float) – Learning rate of optimization. Defaults to
0.01.iteration (int) – Total training iteration. Defaults to
200.saved_dir (str) – The path for saving the fitted data. Defaults to
''.model_name (str) – The model name. Defaults to
linear.
- Returns:
 Trained model
- Return type:
 None
- predict(X)
 Predict value based on current model parameters
- Parameters:
 X (Tensor | ndarray) – Independent data in a 2D array. Every column indicates an independent variable. Every row indicates a sample of data.
- Returns:
 predicted value
- Return type:
 Tensor | ndarray
- score(X, y, metric='r2_score')
 Quantifying the quality of predictions given test set
- Parameters:
 X (Tensor | ndarray) – Independent data in a 2D array. Every column indicates an independent variable. Every row indicates a sample of data.
y (Tensor | ndarray) – Dependent data in a 1D array.
metric (str | Callable) – The metric name for the quality. Defaults to
r2. If the metric is a callable function, the function should be in the expressionfunction(y_true – np.ndarray, y_pred: np.ndarray) -> float.
- Returns:
 The model score. Based on sklearn.metric class.
- Return type:
 float
- class paddle_quantum.data_analysis.vqr.PolyRegression(num_qubits, order=1)
 Bases:
LayerRegression class for initializing a quantum polynomial regression model
- Parameters:
 num_qubits (int) – The number of qubits which the quantum circuit contains.
order (int) – The order of the polynomial regression model. Defaults to
1.
- property reg_param: Tensor
 Flattened parameters in the Layer.
- set_params(new_params)
 set parameters of the model.
- Parameters:
 params – New parameters
- fit(X, y, learning_rate=0.01, iteration=200, saved_dir='', model_name='poly')
 Fitting method used for training the model
- Parameters:
 X (Tensor | ndarray) – Independent data in a 2D array.
y (Tensor | ndarray) – Dependent data in an 1D array.
learning_rate (float) – Learning rate of optimization. Defaults to
0.01.iteration (int) – Total training iteration. Defaults to
200.saved_dir (str) – The path for saving the fitted data. Defaults to
''.model_name (str) – The model name. Defaults to
poly.
- Returns:
 Trained model
- Return type:
 None
- predict(X)
 Predict value based on current model parameters
- Parameters:
 x – A sample of data in an array.
- Returns:
 predicted value
- Return type:
 Tensor | ndarray
- score(X, y, metric='r2_score')
 Quantifying the quality of predictions given test set
- Parameters:
 X (Tensor | ndarray) – Independent data in a 2D array. Every column indicates an independent variable. Every row indicates a sample of data.
y (Tensor | ndarray) – Dependent data in a 1D array.
metric (str | Callable) – The metric name for the quality. Defaults to
r2. If the metric is a callable function, the function should be in the expressionfunction(y_true – np.ndarray, y_pred: np.ndarray) -> float.
- Returns:
 The model score. Based on sklearn.metric class.
- Return type:
 float