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

การนำเข้าข้อมูล Auto MPG สำหรับ Basic Regression ด้วย TensorFlow


บทนำ

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.MPGCylindersDisplacementhorsepowerweightAccelerationModel YearOrigin
018.08307.0130.03504.012.0701
115.08350.0165.03693.011.5701

คำอธิบาย

  • นำเข้าแพ็กเกจที่จำเป็นและตั้งชื่อย่อ
  • โหลดข้อมูลจาก URL กำหนดชื่อคอลัมน์ จัดการค่าที่ขาดหาย
  • แสดงตัวอย่าง 2 แถวแรกของชุดข้อมูล