Tf.contrib.learn.LinearRegressor creates an unexpectedly bad model for single-function data

I am creating a simple linear regression for data from csv . Data includes weight and height values ​​for some people. The general learning process is very simple:

MAX_STEPS = 2000
# ...
features = [tf.contrib.layers.real_valued_column(feature_name) for feature_name in FEATURES_COL]
# ...
linear_regressor = tf.contrib.learn.LinearRegressor(feature_columns=features)
linear_regressor.fit(input_fn=prepare_input, max_steps=MAX_STEPS)

However, the model created by the regressor is unexpectedly bad. The result can be illustrated by the following figure: enter image description here

Visualization Code (just in case):

plt.plot(height_and_weight_df_filtered[WEIGHT_COL], 
         linear_regressor.predict(input_fn=prepare_full_input), 
         color='blue',
         linewidth=3)

Here is the same data given to the LinearRegression class from scikit-learn:

lr_updated = linear_model.LinearRegression()
lr_updated.fit(weight_filtered_reshaped, height_filtered)

And visualization: enter image description here

An increase in the number of steps is not affected. I would suggest that I use the TensorFlow regressor incorrectly.

iPython laptop with code.

+4
source share
2

, TF . , - 200K , , sklearn.

, :

  • sklearn , , . TF LinearRegressor FtrlOptimizer. , .
  • input_fn , . , , FtrlOptimizer , .

, , ( 0,2) 4 . :

linear_regressor = tf.contrib.learn.LinearRegressor(
    feature_columns=features, 
    optimizer=tf.train.FtrlOptimizer(learning_rate=5.0))
+6

. , , _fn . , , .

0

Source: https://habr.com/ru/post/1661536/


All Articles