พล็อตกราฟการ interpolation
การสร้างกราฟเปรียบเทียบผลการ imputation ถือเป็นขั้นตอนสำคัญในการประเมินว่าเทคนิคใดให้ผลดีที่สุด ในแบบฝึกหัดนี้ จะสร้าง for loop เพื่อสร้างกราฟสำหรับหลายเทคนิค imputation โดยจะพล็อตผลการ interpolation ที่ทำไปในบทเรียนก่อนหน้า ได้แก่ linear, quadratic และ nearest interpolation
มีการนำเข้า DataFrame สามชุดที่ตั้งชื่อตามเทคนิค imputation ให้แล้ว ได้แก่ linear_interp, quadratic_interp และ nearest_interp
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การจัดการข้อมูลที่หายไปใน Python
คำแนะนำการฝึกหัด
- สร้าง subplot จำนวน 3 อันสำหรับแต่ละเทคนิค imputation
- สร้าง dictionary
interpolationsโดย map DataFramelinear_interp,quadratic_interpและnearest_interpเข้ากับเทคนิค interpolation ที่เกี่ยวข้อง - วน loop ผ่าน
axesและinterpolations - เลือก DataFrame แต่ละชุดใน
interpolationsและตั้งชื่อกราฟโดยใช้df_key
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Set nrows to 3 and ncols to 1
fig, axes = plt.subplots(___, ___, figsize=(30, 20))
# Create a dictionary of interpolated DataFrames for looping
interpolations = {'Linear Interpolation': ___, 'Quadratic Interpolation': ___,
'Nearest Interpolation': ___}
# Loop over axes and interpolations
for ax, df_key in zip(___, ___):
# Select and also set the title for a DataFrame
interpolations[___].Ozone.plot(color='red', marker='o', linestyle='dotted', ax=ax)
airquality.Ozone.plot(title=___ + ' - Ozone', marker='o', ax=ax)
plt.show()