• Members 2 posts
    Sept. 7, 2021, 7:52 p.m.

    I want to train a multi class neural network, and could only find this in Qiskit MultiClassObjectiveFunction. How can I use this to fit and predict values?
    Link to documentation

  • Members 22 posts
    Sept. 7, 2021, 10:04 p.m.

    The MultiClassObjectiveFunction is included in NeuralNetworkClassifier or other Classifier and Regressors, which means the classifier will automatically choose between BinaryObjectiveFunction and MultiClassObjectiveFunction when you feed the data and request the fit() function.

    You can find this at line 88-103 in the source code neural_network_classifier.py.

    You need to specify the number of output classes when we contruct the neural network.

    output_shape = 3  # corresponds to the number of classes, possible outcomes of the (parity) mapping.
    # construct QNN
    circuit_qnn = CircuitQNN(circuit=qc,
                             input_params=feature_map.parameters,
                             weight_params=ansatz.parameters,
                             interpret=parity,
                             output_shape=output_shape,
                             quantum_instance=quantum_instance)
    # construct classifier
    circuit_classifier = NeuralNetworkClassifier(neural_network=circuit_qnn,
                                                 optimizer=COBYLA())
    # fit classifier to data
    circuit_classifier.fit(X, y01)
    
    

    qiskit QML tutorial block [10] gives a good example.