บทนำ
TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python ใช้ในงานวิจัยและการผลิต
การติดตั้ง
pip install tensorflow
Tensor และปัญหา Regression
เทนเซอร์ = อาร์เรย์หลายมิติ สำหรับ Data flow graph ทำนายตัวแปรต่อเนื่อง
ชุดข้อมูล Auto MPG
ข้อมูลรถยนต์ยุค 70-80s คุณสมบัติ: น้ำหนัก แรงม้า ปริมาตรเครื่องยนต์ ฯลฯ ทำนาย MPG
ตัวอย่าง: โหลดข้อมูลและแสดงตัวอย่าง
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
np.set_printoptions(precision=3, suppress=True)
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.layers.experimental import preprocessing
print("TensorFlow version:")
print(tf.__version__)
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data'
column_names = ['MPG', 'Cylinders', 'Displacement', 'Horsepower', 'Weight', 'Acceleration', 'Model Year', 'Origin']
print("กำลังโหลดข้อมูล")
print("กำหนดชื่อคอลัมน์")
raw_dataset = pd.read_csv(url, names=column_names, na_values='?', comment='\t', sep=' ', skipinitialspace=True)
dataset = raw_dataset.copy()
print("ตัวอย่างข้อมูล:")
dataset.head(2)
ที่มา: TensorFlow Regression Tutorial
ผลลัพธ์
TensorFlow version: 2.4.0 กำลังโหลดข้อมูล กำหนดชื่อคอลัมน์ ตัวอย่างข้อมูล
| sl. | MPG | Cylinders | Displacement | horsepower | weight | Acceleration | Model Year | Origin |
|---|---|---|---|---|---|---|---|---|
| 0 | 18.0 | 8 | 307.0 | 130.0 | 3504.0 | 12.0 | 70 | 1 |
| 1 | 15.0 | 8 | 350.0 | 165.0 | 3693.0 | 11.5 | 70 | 1 |
คำอธิบาย
- นำเข้าแพ็กเกจที่จำเป็นและตั้งชื่อย่อ
- โหลดข้อมูลจาก URL กำหนดชื่อคอลัมน์ จัดการค่าที่ขาดหาย
- แสดงตัวอย่าง 2 แถวแรกของชุดข้อมูล