Module 'sklearn.preprocessing' has no attribute 'Normalization'

I am in the health cost regression task from the machine learning path. I am in the step where I want to create my model and for that I have to normalize my datas. If I wanna do that like its in the tensorflow doc Basic regression: Predict fuel efficiency  |  TensorFlow Core then I get the following error:

module 'sklearn.preprocessing' has no attribute 

Here is how my code looks like for that issue:

normalizer = preprocessing.Normalization(axis=-1)

Here are my imports (I added more eventually possible imports but nothing worked):

# Import libraries. You may or may not use all of these.
!pip install -q git+https://github.com/tensorflow/docs
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn import preprocessing
try:
  # %tensorflow_version only exists in Colab.
  %tensorflow_version 2.x
except Exception:
  pass
import tensorflow as tf

from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.layers import Normalization
import tensorflow_docs as tfdocs
import tensorflow_docs.plots
import tensorflow_docs.modeling
from keras import backend
from keras.engine import base_preprocessing_layer

Would be thankful for some advice.

Looking at that page, it seems to be importing preprocessing from keras, not sklearn:
from tensorflow.keras.layers.experimental import preprocessing

However the Normalization you seem to have imported in the code already:
from tensorflow.keras.layers import Normalization

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.