I am following a tutorial on TensorFlow 2.0 (https://www.youtube.com/watch?v=tPYj3fFJGjk&t=6151s&ab_channel=freeCodeCamp.org) and following the code used in the video. I have it pretty much identical to the one in the video with the exception that I am running my code on my local macos machine and not jupiter notebooks. However, my current code currently displays a lot of warnings about how the functions used are deprecated and will be removed in a future version.
I tried suppressing the warnings but that didn't fix it. The warnings still appeared
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)
warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=PendingDeprecationWarning)
Current Code:
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np import pandas as pd import tensorflow as tf import matplotlib.pyplot as plt from tensorflow import feature_column as fc import ssl
ssl._create_default_https_context = ssl._create_unverified_context dftrain = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/train.csv')
# training data dfeval = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/eval.csv')
# testing data y_train = dftrain.pop('survived') y_eval = dfeval.pop('survived') CATEGORICAL_COLUMNS = ['sex', 'n_siblings_spouses', 'parch', 'class', 'deck','embark_town', 'alone'] NUMERIC_COLUMNS = ['age', 'fare']
feature_columns = [] for feature_name in CATEGORICAL_COLUMNS:
vocabulary = dftrain[feature_name].unique() # If feature_name == 'sex', vocabulary = ['male', 'female']
feature_columns.append(tf.feature_column.categorical_column_with_vocabulary_list(feature_name, vocabulary)) # Creates feature column for each categorical column
for feature_name in NUMERIC_COLUMNS:
feature_columns.append(tf.feature_column.numeric_column(feature_name, dtype=tf.float32)) # Creates feature column for each categorical column def make_input_fn(data_df, label_df, num_epochs=10, shuffle=True, batch_size=32): def input_function(): # inner function, this will be returned
# create tf.data.Dataset object with input data and its label (output data)
ds = tf.data.Dataset.from_tensor_slices((dict(data_df), label_df)) # create tf.data.Dataset object with data and its label
if shuffle:
ds = ds.shuffle(1000) # randomize order of data
ds = ds.batch(batch_size).repeat(num_epochs) # split dataset into batches of 32 and repeat process for number of epochs
return ds # return a batch of the dataset return input_function # return a function object for use
train_input_fn = make_input_fn(dftrain, y_train) # here we will call the input_function that was returned to us to get a dataset object we can feed to the model eval_input_fn = make_input_fn(dfeval, y_eval, num_epochs=1, shuffle=False) linear_est = tf.estimator.LinearClassifier(feature_columns=feature_columns)
linear_est.train(train_input_fn) # train result = linear_est.evaluate(eval_input_fn) # get model metrics/stats by testing on tetsing data print(result['accuracy']) # the result variable is simply a dict of stats about our model
running this code displays (I only pasted some of the warnings here):
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tensorflow/python/training/monitored_session.py:1474: SessionRunValues.__new__ (from tensorflow.python.training.session_run_hook) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
WARNING:tensorflow:From /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tensorflow/python/training/evaluation.py:260: FinalOpsHook.__init__ (from tensorflow.python.training.basic_session_run_hooks) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.keras instead.
2023-05-24 23:50:24.860561: I tensorflow/core/common_runtime/executor.cc:1210] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'Placeholder/_4' with dtype string and shape [264]
[[{{node Placeholder/_4}}]]
0.7348485