'TENSORFLOW: UNSUPPORTABLE CALLABLE
I am trying to build the following model but am getting this error when I am finally training the model and trying to get it's accuracy. It gets stuck when I am feedingg in the trainiing data in my linear model to train it. Here is the whole code->
# Importing all needed libraries to build the model->
import tensorflow as tf
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import clear_output
from six.moves import urllib
import tensorflow.compat.v2.feature_column as fc
print("All modules imported.")
# Loading a data_set to train our model-->
training_data = pd.read_csv("Real estate.csv")
testing_data = pd.read_csv("Real estate eval.csv")
# print(training_data.head())
y_train = training_data.pop("Y house price of unit area")
y_test = testing_data.pop("Y house price of unit area")
# print(training_data.head())
print(y_train)
print(y_test)
numerical_colunms = ["No","X1 transaction date","age","X3 distance to the nearest MRT station","X4 number of convenience stores",
"X5 latitude","X6 longitude"]
feature_colunms=[]
for feature_name in numerical_colunms:
print(feature_name)
feature_colunms.append(tf.feature_column.numeric_column(feature_name,dtype=tf.float32))
print(feature_colunms)
# Making an input function to ddistribute our data into vatches,batch size and define the no.of epochs->
def make_input_fn(data_df, y_df, num_epochs=10,shuffle=True,batch_size=32):
def input_function():
ds = tf.data.Dataset.from_tensor_slices(dict(data_df),y_df)
if shuffle:
ds = ds.shuffle(1000)
ds = ds.batch(batch_size).repeat(num_epochs)
return ds
# This would be returning a function object for use->
return input_function
# Finally preparing the objects for training and testing data that shall be fedd into our model->
training_data_input = make_input_fn(training_data,y_train)
testing_data_input = make_input_fn(testing_data,y_test,num_epochs=1,shuffle=True)
# Actuallu making the linear model :)
linear_model = tf.estimator.LinearClassifier(feature_columns=feature_colunms)
# Training the model built=>>
linear_model.train(training_data_input)
results = linear_model.evaluate(testing_data_input)
clear_output()
print(f"The accuracy of the model ia >> {results['accuracy']}")
The main error is showing here-
linear_model.train(training_data_input)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|