Skip to content

Instantly share code, notes, and snippets.

@santiviquez
Created December 15, 2023 13:37
Show Gist options
  • Select an option

  • Save santiviquez/36282f6fc6115e33c5c650141345baf3 to your computer and use it in GitHub Desktop.

Select an option

Save santiviquez/36282f6fc6115e33c5c650141345baf3 to your computer and use it in GitHub Desktop.
js_distance_toy_example.py
import numpy as np
import pandas as pd
import nannyml as nml
import matplotlib.pyplot as plt
reference_df = pd.DataFrame({'feature': np.random.normal(0, 0.1, 3000)})
analysis_df = pd.DataFrame({'feature': np.random.normal(0, 0.12, 3000)})
calc = nml.UnivariateDriftCalculator(
column_names=['feature'],
continuous_methods=['jensen_shannon'],
chunk_size=1000
)
calc.fit(reference_df)
results = calc.calculate(analysis_df)
results.plot(kind='drift').show()
results.plot(kind='distribution').show()
plt.hist(reference_df.feature, 30, density=True)
plt.hist(analysis_df.feature, 30, density=True)
plt.show()
@santiviquez
Copy link
Copy Markdown
Author

The example above returns the following results.

JS-distance for analysis chunks close to 0.1
Screenshot 2023-12-15 at 14 33 27

Screenshot 2023-12-15 at 14 33 34 Screenshot 2023-12-15 at 14 33 56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment