CommencerCommencer gratuitement

Plot interpolations

Plotting comparative graphs for the imputations is essential for inferring the best imputation technique. In this exercise, you'll create a for loop for generating plots for multiple imputation techniques. You will create the plots of the imputations you performed in the previous lesson i.e., the linear, the quadratic, and the nearest interpolation techniques.

Three DataFrames named after their imputation techniques have already been imported for you, namely, linear_interp, quadratic_interp, and nearest_interp

Cet exercice fait partie du cours

Dealing with Missing Data in Python

Afficher le cours

Instructions

  • Create 3 subplots for each imputation technique.
  • Create the interpolations dictionary by mapping the linear_interp, quadratic_interp, and nearest_interp DataFrames to the relevant interpolation technique.
  • Loop over axes and interpolations.
  • Select each DataFrame in interpolations and set the title for a DataFrame using df_key.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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()
Modifier et exécuter le code