I am following this tutorial and I got into a value error, I tried looking to create numpy array but couldn’t find any.
Here’s the code
import ssl
import numpy as np
import pandas as pd
import tensorflow as tf
from tensorflow import keras
from keras import layersprint(tf.version)
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn’t verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn’t support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_contextdataset_url = ‘http://storage.googleapis.com/download.tensorflow.org/data/petfinder-mini.zip’
csv_file = ‘datasets/petfinder-mini/petfinder-mini.csv’tf.keras.utils.get_file(‘petfinder_mini.zip’, dataset_url,
extract=True, cache_dir=‘.’)
dataframe = pd.read_csv(csv_file)print(dataframe.head())
#In the original dataset, ‘AdoptionSpeed’ of ‘4’ indicates a pet was not adopted
dataframe[‘target’] = np.where(dataframe[‘AdoptionSpeed’] == 4, 0, 1)#Drop unused features
dataframe = dataframe.drop(columns=[‘AdoptionSpeed’, ‘Description’])train, val, test = np.split(dataframe.sample(frac=1), [int(0.8len(dataframe)), int(0.9len(dataframe))])
print(len(train), ‘training examples’)
print(len(val), ‘validation examples’)
print(len(test), ‘test examples’)def df_to_dataset(dataframe, shuffle=True, batch_size=32):
df = dataframe.copy()
labels = df.pop(‘target’)
df = {key: value[:,tf.newaxis] for key, value in dataframe.items()}
ds = tf.data.Dataset.from_tensor_slices((dict(df), labels))
if shuffle:
ds = ds.shuffle(buffer_size=len(dataframe))
ds = ds.batch(batch_size)
ds = ds.prefetch(batch_size)
return dsbatch_size = 5
train_ds = df_to_dataset(train, batch_size=batch_size)[(train_features, label_batch)] = train_ds.take(1)
print(‘Every feature:’, list(train_features.keys()))
print(‘A batch of ages:’, train_features[‘Age’])
print(‘A batch of targets:’, label_batch)