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

Huấn luyện mô hình (fit data) 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ụ

print("Fit dữ liệu train vào mô hình")
history = hrspwr_model.fit(
    train_features['Horsepower'], train_labels,
    epochs=150,
    verbose=0,
    validation_split=0.3)

hist = pd.DataFrame(history.history)
hist['epoch'] = history.epoch
hist.tail()

Nguồn mã: TensorFlow Regression Tutorial

Đầu ra

Huấn luyện mô hình (fit data) trên Auto MPG dataset với TensorFlow

Giải thích

  • Huấn luyện dữ liệu bằng hàm fit().
  • Định số bước huấn luyện qua tham số epochs.
  • Object history lưu tiến độ thống kê huấn luyện.
  • Chuyển history thành DataFrame pandas.
  • Hiển thị mẫu dữ liệu cuối (tail) và trực quan hóa.