Simple linear regression with Tensorflow and SKCompat

160 views Asked by At

Since the update to Tensorflow-GPU 1.3 the estimator is deprecated and has now to be wrapepd into SKCompat class.

The wrapping worked, however I do not how to use the fit function in comparison to the estimator fit function.

The fit function shall take two x arguments, to one y value. Thus, both x's are a Tensor Rank 0.

On the one hand I tried to parse it into the fit argument as numpy arrays, like this:

with tf.device('/gpu:0'): #with tf.device('/cpu:0'):
    #Read the data
    x1_d,x2_d, y_d=readData()

    features = [tf.contrib.layers.real_valued_column("x1",dimension=1),\
                tf.contrib.layers.real_valued_column("x2",dimension=1)]


    cl = SKCompat( tf.contrib.learn.LinearRegressor(feature_columns=features,\
    model_dir='./linear_estimator_2'))


    cl.fit(x={"x1":x1_d,"x2":x2_d},y=y_d)

Which gave me the error

AttributeError: 'numpy.ndarray' object has no attribute 'items'

So I tried to convert it to Tensors like this:

x1_t = tf.convert_to_tensor(x1_d)
x2_t = tf.convert_to_tensor(x2_d)  
y_t = tf.convert_to_tensor(y_d)

cl.fit(x={"x1":x1_t,"x2":x2_t},y=y_t)

Which gave me the error

ValueError: Inputs cannot be tensors. Please provide input_fn

However, if I create input_fn like this:

input_fn_train = tf.contrib.learn.io.numpy_input_fn(
                     {"x1":x1_d,"x2":x2_d}, y_d, num_epochs=1000)
cl.fit(input_fn_train)

Then of course I get the error, that the y-parameter is missing.

So how do I have to set up the data for the fit function of SKCompat?

The questions like Tensorflow Deprecated Warning do not discuss this part, or are from an older version.

0

There are 0 answers