Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Đánh giá mô hình trên Auto MPG dataset với TensorFlow


TensorFlow (Google) framework học máy mã nguồn mở. Cài đặt: pip install tensorflow. Tensor: mảng đa chiều.

Bài toán hồi quy: dự đoán biến liên tục. Dữ liệu Auto MPG: xe hơi thập niên 70-80. Dự đoán MPG.

Chạy trên Google Colab (Python trên trình duyệt, GPU miễn phí).

Ví dụ

def plot_loss(history):
    plt.plot(history.history['loss'], label='loss')
    plt.plot(history.history['val_loss'], label='val_loss')
    plt.ylim([0, 10])
    plt.xlabel('Epoch')
    plt.ylabel('Error [MPG]')
    plt.legend()
    plt.grid(True)

plot_loss(history)

test_results = {}
test_results['hrspwr_model'] = hrspwr_model.evaluate(
    test_features['Horsepower'],
    test_labels, verbose=0)

Nguồn mã: TensorFlow Regression Tutorial

Đầu ra

Đánh giá mô hình trên Auto MPG dataset với TensorFlow

Giải thích

  • Hàm evaluate() đo lường khả năng khái quát của mô hình trên dữ liệu chưa từng thấy.
  • Trực quan hóa loss train/validation qua epochs bằng matplotlib.