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

Dự đoán trên Auto MPG dataset với TensorFlow


TensorFlow (Google) là framework học máy mã nguồn mở, dùng Python. Tensor: mảng đa chiều với Rank, Type, Shape.

Bài toán hồi quy: dự đoán biến liên tục. Dữ liệu Auto MPG: hiệu suất 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("Xem dự đoán như hàm của biến đầu vào")
x = tf.linspace(0.0, 250, 251)
y = hrspwr_model.predict(x)

def plot_horsepower(x, y):
    plt.scatter(train_features['Horsepower'], train_labels, label='Giá trị thực tế')
    plt.plot(x, y, color='g', label='Dự đoán')
    plt.xlabel('Horsepower')
    plt.ylabel('MPG')
    plt.legend()

plot_horsepower(x, y)

Nguồn mã: TensorFlow Regression Tutorial

Đầu ra

Dự đoán trên Auto MPG dataset với TensorFlow

Giải thích

  • Dự đoán giá trị MPG từ mã lực (Horsepower).
  • Vẽ biểu đồ so sánh giá trị thực tế và dự đoán bằng matplotlib.
  • Quan sát dự đoán của mô hình như hàm của dữ liệu đầu vào.