期待値を作成

Great Expectationsで始めるデータ品質入門

Davina Moossazadeh

Data Scientist

Expectations

「Expectation」:データに関する検証可能な主張

  • 列に関する Expectation
  • 形状とスキーマに関する Expectation
    • 「schema」:データセット構造の設計図
1 https://docs.greatexpectations.io/docs/reference/learn/terms/expectation
Great Expectationsで始めるデータ品質入門

Expectations

「Expectation」:データに関する検証可能な主張

  • 列に関する Expectation
  • 形状とスキーマに関する Expectation
    • 「schema」:データセット構造の設計図
1 https://docs.greatexpectations.io/docs/reference/learn/terms/expectation
Great Expectationsで始めるデータ品質入門

再生可能エネルギー発電データセット

再生可能エネルギー発電データを含む pandas DataFrame。「Time」「Energy delta[Wh]」「GHI」「temp」「pressure」「humidity」「wind_speed」「rain_1h」「snow_1h」「clouds_all」の列があり、118,066 行。

1 https://www.kaggle.com/datasets/pythonafroz/renewable-power-generation-and-weather-conditions
Great Expectationsで始めるデータ品質入門

Expectation の作成

gx.expectations.Expect...(...)

GXのクラス(Expectation):PascalCase

GXの関数/メソッド:snake_case

1 https://docs.greatexpectations.io/docs/core/define_expectations/create_an_expectation/
Great Expectationsで始めるデータ品質入門

Expectation の作成

row_count_expectation = gx.expectations.ExpectTableRowCountToEqual(

value=118000 )
validation_results = batch.validate(
expect=row_count_expectation )
1 https://docs.greatexpectations.io/docs/core/define_expectations/create_an_expectation/ https://docs.greatexpectations.io/docs/core/define_expectations/test_an_expectation/
Great Expectationsで始めるデータ品質入門

Expectation の評価

print(validation_results)
{ 
    "success": false,
    "expectation_config": {
        "type": "expect_table_row_count_to_equal",
        "kwargs": {"batch_id": "my_pandas_datasource-my_dataframe_asset", "value": 118000},
        "meta": {},
        "rendered_content": [{"name": "atomic.prescriptive.summary", "value": {"schema": {"type": "com.superconductive.rendered.string"}, "template": "Must have exactly $value rows.", "params": {"value": {"schema": {"type": "number"}, "value": 118000}}}, "value_type": "StringValueType"}]
    },
    "result": {"observed_value": 118066},
    "meta": {},
    "exception_info": {"raised_exception": false, "exception_traceback": null, "exception_message": null},
    "rendered_content": [{"name": "atomic.diagnostic.observed_value", "value": {"schema": {"type": "com.superconductive.rendered.string"}, "template": "118066", "params": {}}, "value_type": "StringValueType"}]
}
1 https://docs.greatexpectations.io/docs/core/run_validations/run_a_validation_definition/
Great Expectationsで始めるデータ品質入門

Expectation の評価

print(validation_results.describe())
{
    "expectation_type": "expect_table_row_count_to_equal",
    "success": false,
    "kwargs": {
        "batch_id": "my_pandas_datasource-my_dataframe_asset",
        "value": 118000
    },
    "result": {
        "observed_value": 118066
    }
}
Great Expectationsで始めるデータ品質入門

Expectation の評価

print(validation_results.success)
False
print(validation_results["success"])
False
Great Expectationsで始めるデータ品質入門

Expectation の評価

print(validation_results.result)
{'observed_value': 118066}
print(validation_results["result"])
{'observed_value': 118066}
Great Expectationsで始めるデータ品質入門

一般的な Expectation 例

形状に関する Expectation:

ExpectTableRowCountToEqual(value: int)
ExpectTableRowCountToBeBetween(
    min_value: int, max_value: int
)
ExpectTableColumnCountToEqual(
    value: int
)
ExpectTableColumnCountToBeBetween(
    min_value: int, max_value: int
)

列名に関する Expectation:

ExpectTableColumnsToMatchSet(
    column_set: set
)
ExpectColumnToExist(column: str)
Great Expectationsで始めるデータ品質入門

チートシート

Expectation を作成:

gx.expectations.Expect...(...)

Expectation を検証:

validation_results = batch.validate(
    expect=expectation
)

行数の Expectation を作成:

expectation = gx.expectations. \
ExpectTableRowCountToEqual(
    value: int
)

検証結果を確認:

validation_results.describe()
validation_results.success
validation_results.result
Great Expectationsで始めるデータ品質入門

Ayo berlatih!

Great Expectationsで始めるデータ品質入門

Preparing Video For Download...