Example for "how to use the neural network class and use the respected methods for the desired output". Calls the TwoHiddenLayerNeuralNetwork class and provides the fixed input output values to the model. Model is trained for a fixed amount of iterations then the predict method
()
| 250 | |
| 251 | |
| 252 | def example() -> int: |
| 253 | """ |
| 254 | Example for "how to use the neural network class and use the |
| 255 | respected methods for the desired output". |
| 256 | Calls the TwoHiddenLayerNeuralNetwork class and |
| 257 | provides the fixed input output values to the model. |
| 258 | Model is trained for a fixed amount of iterations then the predict method is called. |
| 259 | In this example the output is divided into 2 classes i.e. binary classification, |
| 260 | the two classes are represented by '0' and '1'. |
| 261 | |
| 262 | >>> example() in (0, 1) |
| 263 | True |
| 264 | """ |
| 265 | # Input values. |
| 266 | test_input = np.array( |
| 267 | ( |
| 268 | [0, 0, 0], |
| 269 | [0, 0, 1], |
| 270 | [0, 1, 0], |
| 271 | [0, 1, 1], |
| 272 | [1, 0, 0], |
| 273 | [1, 0, 1], |
| 274 | [1, 1, 0], |
| 275 | [1, 1, 1], |
| 276 | ), |
| 277 | dtype=np.float64, |
| 278 | ) |
| 279 | |
| 280 | # True output values for the given input values. |
| 281 | output = np.array(([0], [1], [1], [0], [1], [0], [0], [1]), dtype=np.float64) |
| 282 | |
| 283 | # Calling neural network class. |
| 284 | neural_network = TwoHiddenLayerNeuralNetwork( |
| 285 | input_array=test_input, output_array=output |
| 286 | ) |
| 287 | |
| 288 | # Calling training function. |
| 289 | # Set give_loss to True if you want to see loss in every iteration. |
| 290 | neural_network.train(output=output, iterations=10, give_loss=False) |
| 291 | |
| 292 | return neural_network.predict(np.array(([1, 1, 1]), dtype=np.float64)) |
| 293 | |
| 294 | |
| 295 | if __name__ == "__main__": |
no test coverage detected