Advanced Imputation and Reporting¶
This notebook demonstrates some of the more advanced features of missingly, including MICE imputation, visualizing the results of imputation, and generating an HTML report.
1. The Dataset¶
[1]:
import pandas as pd
import numpy as np
import missingly as mi
np.random.seed(42)
data = {
'temperature': np.random.normal(100, 5, 100),
'pressure': np.random.normal(50, 2, 100),
'humidity': np.random.normal(40, 5, 100)
}
df = pd.DataFrame(data)
# Introduce some missing values
df.loc[df.sample(frac=0.1).index, 'temperature'] = np.nan
df.loc[df.sample(frac=0.15).index, 'pressure'] = np.nan
df.head()
[1]:
| temperature | pressure | humidity | |
|---|---|---|---|
| 0 | 102.483571 | 47.169259 | 41.788937 |
| 1 | 99.308678 | 49.158709 | 42.803923 |
| 2 | 103.238443 | 49.314571 | 45.415256 |
| 3 | 107.615149 | NaN | 45.269010 |
| 4 | 98.829233 | 49.677429 | 33.111653 |
2. MICE Imputation¶
[2]:
df_imputed_mice = mi.impute_mice(df)
3. Visualizing the Imputation¶
[3]:
mi.vis_impute_dist(df, df_imputed_mice, 'temperature')
[3]:
<Axes: title={'center': "Distribution of 'temperature': before vs after imputation"}, xlabel='temperature', ylabel='Count'>
4. Generating an HTML Report¶
[4]:
mi.create_report(df, output_path='missingly_report.html')
[4]:
'/home/runner/work/missingly/missingly/docs/source/examples/missingly_report.html'