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

Cách tải dữ liệu CSV từ tập abalone với TensorFlow

Tập abalone được tải từ Google API lưu trữ dataset. Dùng pd.read_csv() của Pandas để đọc từ URL vào DataFrame. Tên các feature được chỉ định rõ ràng.

Mã ví dụ

import pandas as pd
import numpy as np
print("Cấu hình hiển thị NumPy dễ đọc")
np.set_printoptions(precision=3, suppress=True)

import tensorflow as tf
from tensorflow.keras import layers
from tensorflow.keras.layers.experimental import preprocessing

print("Đang đọc dữ liệu CSV")
abalone_train = pd.read_csv(
    "https://storage.googleapis.com/download.tensorflow.org/data/abalone_train.csv",
    names=["Length", "Diameter", "Height", "Whole weight", "Shucked weight",
           "Viscera weight", "Shell weight", "Age"])

Nguồn mã: TensorFlow CSV Tutorial

Đầu ra

Cấu hình hiển thị NumPy dễ đọc
Đang đọc dữ liệu CSV

Giải thích

  • Cài đặt/gọi các package cần thiết.
  • Đọc CSV bằng read_csv từ URL Google Cloud Storage.
  • Tất cả feature xử lý giống nhau → gói thành một mảng NumPy duy nhất.