Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีแสดงตัวอย่างข้อมูลจาก Abalone Dataset ด้วย TensorFlow

บทนำ

หลังโหลด Abalone dataset ด้วย pandas read_csv ควรตรวจสอบข้อมูลด้วย head() และแยก features/labels ก่อน train

โค้ดตัวอย่าง

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)

ผลลัพธ์

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 ]]

คำอธิบาย

  1. head(): แสดง 5 แถวแรก (default) สำหรับตรวจสอบโครงสร้างข้อมูล
  2. copy(): สร้าง본สำเนา เพื่อไม่แก้ไขข้อมูลต้นฉบับ
  3. pop('Age'): ดึง column 'Age' ออกจาก features และเก็บเป็น labels แยกต่างหาก
  4. np.array(): แปลง DataFrame → NumPy array สำหรับ feed เข้า TensorFlow

ข้อมูล Abalone Dataset

คุณสมบัติ 7-8 features: Length, Diameter, Height, Whole weight, Shucked weight, Viscera weight, Shell weight, Rings (→ Age = Rings + 1.5)

เป้าหมาย: พยากรณ์ Age (regression)