NeuralNetworkClassifier
Bases: Generic[IFT, IPT, OT]
A NeuralNetworkClassifier is a neural network that is used for classification tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_conversion |
InputConversion[IFT, IPT]
|
to convert the input data for the neural network |
required |
layers |
list[Layer]
|
a list of layers for the neural network to learn |
required |
output_conversion |
OutputConversion[IPT, OT]
|
to convert the output data of the neural network back |
required |
Raises:
| Type | Description |
|---|---|
InvalidModelStructureError
|
if the defined model structure is invalid |
Source code in src/safeds/ml/nn/_model.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
is_fitted: bool
property
¶
Whether the model is fitted.
fit(train_data, epoch_size=25, batch_size=1, learning_rate=0.001, callback_on_batch_completion=None, callback_on_epoch_completion=None)
¶
Train the neural network with given training data.
The original model is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data |
IFT
|
The data the network should be trained on. |
required |
epoch_size |
int
|
The number of times the training cycle should be done. |
25
|
batch_size |
int
|
The size of data batches that should be loaded at one time. |
1
|
learning_rate |
float
|
The learning rate of the neural network. |
0.001
|
callback_on_batch_completion |
Callable[[int, float], None] | None
|
Function used to view metrics while training. Gets called after a batch is completed with the index of the last batch and the overall loss average. |
None
|
callback_on_epoch_completion |
Callable[[int, float], None] | None
|
Function used to view metrics while training. Gets called after an epoch is completed with the index of the last epoch and the overall loss average. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
trained_model |
Self
|
The trained Model |
Raises:
| Type | Description |
|---|---|
ValueError
|
If epoch_size < 1 If batch_size < 1 |
Source code in src/safeds/ml/nn/_model.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
predict(test_data)
¶
Make a prediction for the given test data.
The original Model is not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_data |
IPT
|
The data the network should predict. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
prediction |
OT
|
The given test_data with an added "prediction" column at the end |
Raises:
| Type | Description |
|---|---|
ModelNotFittedError
|
If the Model has not been fitted yet |