如何使用Tensorflow顯示來自鮑魚資料集的樣本資料?


一旦使用Google API下載了鮑魚資料集,就可以使用“head”方法在控制檯上顯示一些資料樣本。如果向此方法傳遞一個數字,則將顯示這麼多行。它基本上顯示從開頭開始的行。

閱讀更多: 什麼是 TensorFlow 以及 Keras 如何與 TensorFlow 協作建立神經網路?

我們將使用鮑魚資料集,其中包含一組鮑魚的測量值。鮑魚是一種海蝸牛。目標是根據其他測量值預測年齡。

我們使用 Google Colaboratory 來執行以下程式碼。Google Colab 或 Colaboratory 幫助透過瀏覽器執行 Python 程式碼,無需任何配置,並可以免費訪問 GPU(圖形處理單元)。Colaboratory 建立在 Jupyter Notebook 之上。

print("Few samples of abalone data")
abalone_train.head()
print("The abalone dataset is copied to another memory location")
abalone_features = abalone_train.copy()
print("The age column is deleted")
abalone_labels = abalone_features.pop('Age')
abalone_features = np.array(abalone_features)
print("The features are displayed")
print(abalone_features)

程式碼來源:https://www.tensorflow.org/tutorials/load_data/csv

輸出

Few samples of abalone data
The abalone dataset is copied to another memory location
The age column is deleted
The features are displayed
[[0.435 0.335 0.11   ... 0.136 0.077 0.097]
[0.585 0.45   0.125 ... 0.354 0.207 0.225]
[0.655 0.51   0.16   ... 0.396 0.282 0.37 ]
...
[0.53   0.42   0.13   ... 0.374 0.167 0.249]
[0.395 0.315 0.105 ... 0.118 0.091 0.119]
[0.45   0.355 0.12   ... 0.115 0.067 0.16 ]]

解釋

  • 使用“head”方法在控制檯上顯示了一些資料樣本。
  • 資料集被複制到另一個記憶體位置,以便可以對其中一個數據集進行更改,同時保留另一個記憶體位置中資料集的原始性。
  • 我們認為“年齡”列不相關,因此將其從資料集中刪除。
  • 特徵顯示為向量。

更新於: 2021年2月19日

149 次瀏覽

啟動你的 職業生涯

透過完成課程獲得認證

開始學習
廣告