บทนำ
TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python รองรับ Deep Learning
การติดตั้ง
pip install tensorflow
คุณสมบัติของ Tensor
- Rank - มิติของเทนเซอร์ (order/number of dimensions)
- Type - ชนิดข้อมูลขององค์ประกอบ (1D, 2D, nD)
- Shape - จำนวนแถวและคอลัมน์รวมกัน
ปัญหา Regression และชุดข้อมูล Auto MPG
ทำนายตัวแปรต่อเนื่อง เช่น ราคา ความน่าจะเป็น MPG ชุดข้อมูล Auto MPG มีคุณสมบัติรถยนต์ยุค 70-80s
ตัวอย่าง: ฟังก์ชันสร้างและคอมไพล์โมเดล Sequential
def build_compile_model(norm):
model = keras.Sequential([
norm,
layers.Dense(64, activation='relu'),
layers.Dense(64, activation='relu'),
layers.Dense(1)
])
model.compile(loss='mean_absolute_error',
optimizer=tf.keras.optimizers.Adam(0.001))
return model
print("กำลังสร้างและคอมไพล์โมเดล")
dnn_horsepower_model = build_compile_model(horsepower_normalizer)
print("กำลังคำนวณสรุปสถิติ")
dnn_horsepower_model.summary()
ที่มา: TensorFlow Regression Tutorial
ผลลัพธ์

คำอธิบาย
- กำหนดฟังก์ชัน
build_compile_modelสร้างโมเดล Sequential 3 เลเยอร์ Dense - คอมไพล์โมเดลและคืนค่าเป็นผลลัพธ์
- แสดงการวิเคราะห์สถิติด้วย
summary()