Model Pipeline - Prediction and evaluation
This pipeline shows how a trained TensorFlow model makes predictions on new data and evaluates its performance using accuracy and loss metrics.
Jump into concepts and practice - no test required
This pipeline shows how a trained TensorFlow model makes predictions on new data and evaluates its performance using accuracy and loss metrics.
Loss
1.2 |************
1.0 |********
0.8 |******
0.6 |****
0.4 |**
0.2 |
+----------------
1 2 3 4 5 Epochs
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.45 | Model starts with high loss and low accuracy. |
| 2 | 0.85 | 0.65 | Loss decreases and accuracy improves as model learns. |
| 3 | 0.6 | 0.78 | Model continues to improve with more training. |
| 4 | 0.45 | 0.85 | Loss lowers further and accuracy approaches good performance. |
| 5 | 0.35 | 0.9 | Training converges with low loss and high accuracy. |
model.predict() function do in TensorFlow?model.predict()model.fit(), saving uses model.save(), and deleting is manual memory management, none of which are predict().X_test and y_test?model.evaluate() to measure performance on test data.model.predict() makes predictions, model.fit() trains, and model.score() is not a TensorFlow method.import tensorflow as tf import numpy as np model = tf.keras.Sequential([ tf.keras.layers.Dense(1, input_shape=(1,)) ]) model.compile(optimizer='sgd', loss='mse') X = np.array([1, 2, 3, 4], dtype=float) y = np.array([2, 4, 6, 8], dtype=float) model.fit(X, y, epochs=10, verbose=0) predictions = model.predict(np.array([5.0])) print(predictions)
model.evaluate(X_test, y_test) but get a ValueError about mismatched shapes. What is the most likely cause?X_test1, y_test1 and X_test2, y_test2. Which approach correctly compares their accuracy using TensorFlow?model.evaluate() returns loss and metrics on test data without training, ideal for comparing performance.