如何使用Tensorflow載入來自鮑魚資料集的csv資料?
可以使用儲存此資料集的 Google API 下載鮑魚資料集。Pandas 庫中提供的“read_csv”方法用於將資料從 API 讀取到 CSV 檔案中。特徵名稱也明確指定。
閱讀更多: 什麼是 TensorFlow 以及 Keras 如何與 TensorFlow 協同工作以建立神經網路?
我們將使用鮑魚資料集,其中包含一組鮑魚的測量值。鮑魚是一種海螺。目標是根據其他測量值預測年齡。
我們使用 Google Colaboratory 來執行以下程式碼。Google Colab 或 Colaboratory 幫助在瀏覽器上執行 Python 程式碼,並且無需任何配置即可免費訪問 GPU(圖形處理單元)。Colaboratory 建立在 Jupyter Notebook 之上。
import pandas as pd
import numpy as np
print("The below line makes it easier to read NumPy values")
np.set_printoptions(precision=3, suppress=True)
import tensorflow as tf
from tensorflow.keras import layers
from tensorflow.keras.layers.experimental import preprocessing
print("Reading the csv data")
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"])程式碼來源:https://www.tensorflow.org/tutorials/load_data/csv
輸出
The below line makes it easier to read NumPy values Reading the csv data
解釋
- 將所需的包下載到環境中。
- 使用“read_csv”方法讀取 CSV 資料。
- 資料集中的所有特徵都需要被同等對待。
- 完成後,將特徵包裝到單個 NumPy 陣列中。
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP