Python
model.fit()
error handling
debugging
machine learning

Python model.fit error, None values not supported

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

This model.fit error usually means some part of the training input pipeline is producing None where TensorFlow or Keras expects a real tensor, NumPy array, or numeric value. The fix is not in model.fit itself. The fix is to trace the inputs back to the place where missing or invalid values are being introduced.

Check the Training Data First

The most common cause is ordinary missing data in features or labels. For example, a Pandas column may contain Python None values or mixed object data:

python
1import pandas as pd
2import numpy as np
3
4df = pd.DataFrame(
5    {
6        "x1": [1.0, 2.0, None, 4.0],
7        "x2": [0.5, 1.5, 2.5, 3.5],
8        "y": [0, 1, 0, 1],
9    }
10)
11
12print(df.isna().sum())

If None or NaN is present, clean or impute the data before training:

python
1df = df.dropna()
2
3X = df[["x1", "x2"]].to_numpy(dtype="float32")
4y = df["y"].to_numpy(dtype="float32")

This is the first place to look because it is by far the most common failure mode.

Watch for Object-Dtype Arrays

Even when values look numeric, NumPy arrays can silently end up with dtype=object, especially if None was mixed into the data earlier:

python
1import numpy as np
2
3X = np.array([[1.0, 2.0], [3.0, None]])
4print(X.dtype)

That array is not a clean numeric training tensor. Convert explicitly after fixing the missing values:

python
clean = np.array([[1.0, 2.0], [3.0, 4.0]], dtype="float32")
print(clean.dtype)

If model.fit receives an object array, the error message often looks confusing, but the root cause is still bad input values.

Inspect Generators and tf.data Pipelines

If you are not passing plain NumPy arrays, the None may come from a generator or dataset pipeline. A generator like this will fail:

python
def bad_generator():
    yield [1.0, 2.0], 0
    yield None, 1

Likewise, a tf.data.Dataset pipeline can accidentally emit None through custom mapping code or malformed parsing logic.

A simple debugging step is to inspect the first few batches before training:

python
for batch_x, batch_y in dataset.take(3):
    print(batch_x)
    print(batch_y)

If a batch contains missing values, fix the dataset creation step instead of trying to work around the error in fit.

Check Labels, Not Just Features

Developers often focus on feature matrices and forget the targets. The label array can be the source of the None just as easily:

python
y = np.array([0, 1, None, 0], dtype=object)
print(y)

Make sure both X and y are numeric, shaped correctly, and free of missing values before calling fit.

Validate Shapes and Return Signatures

Sometimes the problem is not literal missing data but a bad function returning None unintentionally. This happens in preprocessing pipelines when a helper forgets to return the transformed array:

python
1def preprocess(X):
2    X = X / 255.0
3    # missing return here
4
5
6X = preprocess(np.array([[0.0, 255.0]], dtype="float32"))
7print(X)  # None

That kind of bug produces the same downstream None values not supported error. When the obvious data-cleaning checks pass, inspect your preprocessing functions for missing returns or accidental in-place assumptions.

Common Pitfalls

The most common mistake is checking only the raw DataFrame and not the final arrays actually passed into model.fit. Missing values can be introduced or preserved during preprocessing.

Another pitfall is assuming NaN and None are interchangeable from the model’s point of view. Both are signs of bad input, but they often enter the pipeline differently and may create object-dtype arrays along the way.

It is also easy to overlook labels, generators, or dataset pipelines and focus only on feature columns. Any part of the (x, y) pair can be the source of the problem.

Finally, do not ignore helper functions that accidentally return None. A missing return statement is a surprisingly common reason this error appears.

Summary

  • The error usually means some part of the input pipeline is emitting None instead of numeric data.
  • Check both features and labels for missing values.
  • Inspect NumPy dtypes and avoid object arrays.
  • Debug generators and tf.data batches directly before calling model.fit.
  • If the data looks clean, inspect preprocessing functions for missing returns or malformed outputs.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.