{"id":1740,"library":"tensorflow-estimator","title":"TensorFlow Estimator","description":"The TensorFlow Estimator library provides a high-level API for training machine learning models, simplifying the process of training, evaluating, and predicting. While still maintained for existing projects, it is officially not recommended for new code, with Keras being the preferred API in modern TensorFlow. It generally follows the TensorFlow core release cadence.","status":"maintenance","version":"2.15.0","language":"en","source_language":"en","source_url":"https://github.com/tensorflow/estimator","tags":["tensorflow","machine-learning","deep-learning","estimator","neural-networks"],"install":[{"cmd":"pip install tensorflow-estimator","lang":"bash","label":"Install only Estimator"},{"cmd":"pip install tensorflow","lang":"bash","label":"Install TensorFlow (includes Estimator)"}],"dependencies":[{"reason":"Estimator is built on TensorFlow and requires it to run. Installing `tensorflow` directly will also install `tensorflow-estimator`.","package":"tensorflow"}],"imports":[{"note":"The canonical way to access Estimator is through the `tf.estimator` namespace after importing `tensorflow`.","wrong":"from tensorflow_estimator.python.estimator import Estimator","symbol":"Estimator","correct":"import tensorflow as tf\nestimator = tf.estimator.Estimator(...)"},{"symbol":"DNNClassifier","correct":"import tensorflow as tf\nclassifier = tf.estimator.DNNClassifier(...)"}],"quickstart":{"code":"import tensorflow as tf\n\n# Define feature columns\nfeature_columns = [\n    tf.feature_column.numeric_column('x', shape=[1])\n]\n\n# Define the estimator\nestimator = tf.estimator.DNNRegressor(\n    feature_columns=feature_columns,\n    hidden_units=[10, 10],\n    model_dir='/tmp/DNNRegressor_model'\n)\n\n# Define input function for training\ndef input_fn_train():\n    features = {'x': tf.constant([1., 2., 3., 4.])}\n    labels = tf.constant([0., -1., -2., -3.])\n    return tf.data.Dataset.from_tensor_slices((features, labels)).repeat().batch(2)\n\n# Define input function for prediction\ndef input_fn_predict():\n    features = {'x': tf.constant([5., 6.])}\n    return tf.data.Dataset.from_tensor_slices(features).batch(2)\n\n# Train the estimator\nprint('Training the model...')\nestimator.train(input_fn=input_fn_train, steps=100)\nprint('Training complete.')\n\n# Predict\nprint('Making predictions...')\npredictions = list(estimator.predict(input_fn=input_fn_predict))\nfor p in predictions:\n    print(f\"Prediction: {p['predictions'][0]:.2f}\")\n","lang":"python","description":"This quickstart demonstrates how to create, train, and make predictions with a `DNNRegressor` using `tf.estimator`. It defines a simple input function for training and prediction, and then trains the model for a few steps before predicting on new data."},"warnings":[{"fix":"For new projects, use `tf.keras.Model` or `tf.keras.Sequential` directly. For existing projects, consider migrating your Estimator code to Keras as part of a modernization effort.","message":"Estimators are not recommended for new code. TensorFlow's official stance is to prefer Keras for new development due to its simpler API, better integration with TF2.x eager execution, and broader community support.","severity":"deprecated","affected_versions":"2.0.0 and later"},{"fix":"If migrating is not feasible, ensure you understand the execution model of Estimators. For advanced use cases or when eager execution is critical, Keras is the recommended path.","message":"Estimators are designed primarily for graph execution in a TF1.x style. While they run in TF2.x, they often hide the underlying TF2.x features and may not fully leverage eager execution in the same way native Keras models do, potentially leading to less intuitive debugging or performance limitations compared to pure Keras.","severity":"gotcha","affected_versions":"2.0.0 and later"},{"fix":"Always install the main `tensorflow` package (e.g., `pip install tensorflow`) to ensure all necessary components, including Estimator, are correctly set up and accessible via `import tensorflow as tf`.","message":"The `tensorflow-estimator` package provides the `tf.estimator` namespace, but it's typically installed automatically as a dependency of the main `tensorflow` package. Manually installing `tensorflow-estimator` without `tensorflow` will not provide a functional `tf.estimator` API unless `tensorflow` is already present or installed separately.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}