Chapter 16
Baseline model for batch monitoring example
NotebookPython 3 (ipykernel)40 cells
Baseline model for batch monitoring example
In [38]python · cell 2
python
import requests
import datetime
import pandas as pd
from evidently import ColumnMapping
from evidently.report import Report
from evidently.metrics import ColumnDriftMetric, DatasetDriftMetric, DatasetMissingValuesMetric
from joblib import load, dump
from tqdm import tqdm
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error, mean_absolute_percentage_errorIn [2]python · cell 3
python
files = [('green_tripdata_2022-02.parquet', './data'), ('green_tripdata_2022-01.parquet', './data')]
print("Download files:")
for file, path in files:
url=f"https://d37ci6vzurychx.cloudfront.net/trip-data/{file}"
resp=requests.get(url, stream=True)
save_path=f"{path}/{file}"
with open(save_path, "wb") as handle:
for data in tqdm(resp.iter_content(),
desc=f"{file}",
postfix=f"save to {save_path}",
total=int(resp.headers["Content-Length"])):
handle.write(data)Output
Download files:
green_tripdata_2022-02.parquet: 100%|█| 1428262/1428262 [00:03<00:00, 434198.31it/s, save to ./data/green_tripdata_2022 green_tripdata_2022-01.parquet: 100%|█| 1254291/1254291 [00:03<00:00, 403711.30it/s, save to ./data/green_tripdata_2022
In [3]python · cell 4
python
jan_data = pd.read_parquet('data/green_tripdata_2022-01.parquet')In [4]python · cell 5
python
jan_data.describe()Output
VendorID lpep_pickup_datetime lpep_dropoff_datetime \
count 62495.000000 62495 62495
mean 1.849508 2022-01-16 14:18:36.026354 2022-01-16 14:37:37.189551
min 1.000000 2009-01-01 00:34:01 2009-01-01 17:05:20
25% 2.000000 2022-01-08 23:41:50 2022-01-08 23:55:28.500000
50% 2.000000 2022-01-16 15:59:42 2022-01-16 16:17:00
75% 2.000000 2022-01-24 09:16:50 2022-01-24 09:37:28
max 2.000000 2022-01-31 23:57:37 2022-02-01 21:01:54
std 0.357556 NaN NaN
RatecodeID PULocationID DOLocationID passenger_count \
count 56200.000000 62495.000000 62495.000000 56200.000000
mean 1.198719 97.615041 135.969902 1.258399
min 1.000000 1.000000 1.000000 0.000000
25% 1.000000 55.000000 74.000000 1.000000
50% 1.000000 75.000000 137.000000 1.000000
75% 1.000000 130.000000 215.000000 1.000000
max 5.000000 265.000000 265.000000 8.000000
std 0.862313 62.987311 77.590956 0.877743
trip_distance fare_amount extra mta_tax tip_amount \
count 62495.000000 62495.000000 62495.00000 62495.000000 62495.000000
mean 77.758632 13.914000 0.34756 0.426322 1.666540
min 0.000000 -65.000000 -4.50000 -0.500000 -0.860000
25% 1.080000 7.000000 0.00000 0.500000 0.000000
50% 1.900000 10.500000 0.00000 0.500000 1.000000
75% 3.500000 17.000000 0.50000 0.500000 2.610000
max 224481.380000 604.500000 4.50000 0.500000 76.770000
std 2909.354163 12.088819 0.65781 0.181381 2.484928
tolls_amount improvement_surcharge total_amount payment_type \
count 62495.000000 62495.000000 62495.000000 56200.000000
mean 0.208182 0.297312 17.490532 1.403594
min -6.550000 -0.300000 -71.850000 1.000000
25% 0.000000 0.300000 9.360000 1.000000
50% 0.000000 0.300000 13.860000 1.000000
75% 0.000000 0.300000 21.050000 2.000000
max 44.750000 0.300000 605.300000 5.000000
std 1.257659 0.037201 13.623416 0.516316
trip_type congestion_surcharge
count 56200.000000 56200.000000
mean 1.040925 0.706628
min 1.000000 0.000000
25% 1.000000 0.000000
50% 1.000000 0.000000
75% 1.000000 2.750000
max 2.000000 2.750000
std 0.198119 1.201632
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
| VendorID | lpep_pickup_datetime | lpep_dropoff_datetime | RatecodeID | PULocationID | DOLocationID | passenger_count | trip_distance | fare_amount | extra | mta_tax | tip_amount | tolls_amount | improvement_surcharge | total_amount | payment_type | trip_type | congestion_surcharge | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 62495.000000 | 62495 | 62495 | 56200.000000 | 62495.000000 | 62495.000000 | 56200.000000 | 62495.000000 | 62495.000000 | 62495.00000 | 62495.000000 | 62495.000000 | 62495.000000 | 62495.000000 | 62495.000000 | 56200.000000 | 56200.000000 | 56200.000000 |
| mean | 1.849508 | 2022-01-16 14:18:36.026354 | 2022-01-16 14:37:37.189551 | 1.198719 | 97.615041 | 135.969902 | 1.258399 | 77.758632 | 13.914000 | 0.34756 | 0.426322 | 1.666540 | 0.208182 | 0.297312 | 17.490532 | 1.403594 | 1.040925 | 0.706628 |
| min | 1.000000 | 2009-01-01 00:34:01 | 2009-01-01 17:05:20 | 1.000000 | 1.000000 | 1.000000 | 0.000000 | 0.000000 | -65.000000 | -4.50000 | -0.500000 | -0.860000 | -6.550000 | -0.300000 | -71.850000 | 1.000000 | 1.000000 | 0.000000 |
| 25% | 2.000000 | 2022-01-08 23:41:50 | 2022-01-08 23:55:28.500000 | 1.000000 | 55.000000 | 74.000000 | 1.000000 | 1.080000 | 7.000000 | 0.00000 | 0.500000 | 0.000000 | 0.000000 | 0.300000 | 9.360000 | 1.000000 | 1.000000 | 0.000000 |
| 50% | 2.000000 | 2022-01-16 15:59:42 | 2022-01-16 16:17:00 | 1.000000 | 75.000000 | 137.000000 | 1.000000 | 1.900000 | 10.500000 | 0.00000 | 0.500000 | 1.000000 | 0.000000 | 0.300000 | 13.860000 | 1.000000 | 1.000000 | 0.000000 |
| 75% | 2.000000 | 2022-01-24 09:16:50 | 2022-01-24 09:37:28 | 1.000000 | 130.000000 | 215.000000 | 1.000000 | 3.500000 | 17.000000 | 0.50000 | 0.500000 | 2.610000 | 0.000000 | 0.300000 | 21.050000 | 2.000000 | 1.000000 | 2.750000 |
| max | 2.000000 | 2022-01-31 23:57:37 | 2022-02-01 21:01:54 | 5.000000 | 265.000000 | 265.000000 | 8.000000 | 224481.380000 | 604.500000 | 4.50000 | 0.500000 | 76.770000 | 44.750000 | 0.300000 | 605.300000 | 5.000000 | 2.000000 | 2.750000 |
| std | 0.357556 | NaN | NaN | 0.862313 | 62.987311 | 77.590956 | 0.877743 | 2909.354163 | 12.088819 | 0.65781 | 0.181381 | 2.484928 | 1.257659 | 0.037201 | 13.623416 | 0.516316 | 0.198119 | 1.201632 |
In [5]python · cell 6
python
jan_data.shapeOutput
(62495, 20)
In [6]python · cell 7
python
# create target
jan_data["duration_min"] = jan_data.lpep_dropoff_datetime - jan_data.lpep_pickup_datetime
jan_data.duration_min = jan_data.duration_min.apply(lambda td : float(td.total_seconds())/60)In [7]python · cell 8
python
# filter out outliers
jan_data = jan_data[(jan_data.duration_min >= 0) & (jan_data.duration_min <= 60)]
jan_data = jan_data[(jan_data.passenger_count > 0) & (jan_data.passenger_count <= 8)]In [28]python · cell 9
python
jan_data.duration_min.hist()Output
<Axes: >
<Figure size 640x480 with 1 Axes>
In [9]python · cell 10
python
# data labeling
target = "duration_min"
num_features = ["passenger_count", "trip_distance", "fare_amount", "total_amount"]
cat_features = ["PULocationID", "DOLocationID"]In [10]python · cell 11
python
jan_data.shapeOutput
(55211, 21)
In [11]python · cell 12
python
train_data = jan_data[:30000]
val_data = jan_data[30000:]In [12]python · cell 13
python
model = LinearRegression()In [13]python · cell 14
python
model.fit(train_data[num_features + cat_features], train_data[target])Output
LinearRegression()
#sk-container-id-1 {color: black;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: "▸";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: "▾";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: "";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression
LinearRegression()
In [14]python · cell 15
python
train_preds = model.predict(train_data[num_features + cat_features])
train_data['prediction'] = train_predsIn [15]python · cell 16
python
val_preds = model.predict(val_data[num_features + cat_features])
val_data['prediction'] = val_predsIn [16]python · cell 17
python
print(mean_absolute_error(train_data.duration_min, train_data.prediction))
print(mean_absolute_error(val_data.duration_min, val_data.prediction))Output
3.804665373785083 4.14206407368847
Dump model and reference data
In [17]python · cell 19
python
with open('models/lin_reg.bin', 'wb') as f_out:
dump(model, f_out)In [18]python · cell 20
python
val_data.to_parquet('data/reference.parquet')Evidently Report
In [19]python · cell 22
python
column_mapping = ColumnMapping(
target=None,
prediction='prediction',
numerical_features=num_features,
categorical_features=cat_features
)In [20]python · cell 23
python
report = Report(metrics=[
ColumnDriftMetric(column_name='prediction'),
DatasetDriftMetric(),
DatasetMissingValuesMetric()
]
)In [21]python · cell 24
python
report.run(reference_data=train_data, current_data=val_data, column_mapping=column_mapping)In [22]python · cell 25
python
report.show(mode='inline')Output
<IPython.core.display.HTML object>
In [23]python · cell 26
python
result = report.as_dict()In [24]python · cell 27
python
resultOutput
{'metrics': [{'metric': 'ColumnDriftMetric',
'result': {'column_name': 'prediction',
'column_type': 'num',
'stattest_name': 'Wasserstein distance (normed)',
'stattest_threshold': 0.1,
'drift_score': 0.030493164661663727,
'drift_detected': False,
'current': {'small_distribution': {'x': [-36.73636669418323,
-15.174383681787852,
6.387599330607529,
27.949582343002902,
49.51156535539829,
71.07354836779368,
92.63553138018904,
114.19751439258442,
135.7594974049798,
157.3214804173752,
178.8834634297706],
'y': [9.197953980857077e-06,
0.0011092732500913634,
0.04410786851980204,
0.001078000206556449,
4.598976990428536e-05,
1.6556317165542753e-05,
1.839590796171415e-06,
3.67918159234283e-06,
1.839590796171415e-06,
3.67918159234283e-06]}},
'reference': {'small_distribution': {'x': [-28.66907196717118,
-9.81048482283424,
9.0481023215027,
27.906689465839644,
46.765276610176585,
65.62386375451352,
84.48245089885047,
103.3410380431874,
122.19962518752435,
141.05821233186128,
159.9167994761982],
'y': [8.837706949680752e-06,
0.014953400158859832,
0.0364414008363136,
0.0014493839397476433,
0.00013433314563514746,
1.7675413899361497e-05,
1.2372789729553065e-05,
3.535082779872299e-06,
1.7675413899361507e-06,
3.5350827798723043e-06]}}}},
{'metric': 'DatasetDriftMetric',
'result': {'drift_share': 0.5,
'number_of_columns': 7,
'number_of_drifted_columns': 0,
'share_of_drifted_columns': 0.0,
'dataset_drift': False}},
{'metric': 'DatasetMissingValuesMetric',
'result': {'current': {'different_missing_values': {'': 0,
-inf: 0,
None: 25211,
inf: 0},
'number_of_different_missing_values': 1,
'different_missing_values_by_column': {'VendorID': {'': 0,
-inf: 0,
None: 0,
inf: 0},
'lpep_pickup_datetime': {'': 0, -inf: 0, None: 0, inf: 0},
'lpep_dropoff_datetime': {'': 0, -inf: 0, None: 0, inf: 0},
'store_and_fwd_flag': {'': 0, -inf: 0, None: 0, inf: 0},
'RatecodeID': {'': 0, -inf: 0, None: 0, inf: 0},
'PULocationID': {'': 0, -inf: 0, None: 0, inf: 0},
'DOLocationID': {'': 0, -inf: 0, None: 0, inf: 0},
'passenger_count': {'': 0, -inf: 0, None: 0, inf: 0},
'trip_distance': {'': 0, -inf: 0, None: 0, inf: 0},
'fare_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'extra': {'': 0, -inf: 0, None: 0, inf: 0},
'mta_tax': {'': 0, -inf: 0, None: 0, inf: 0},
'tip_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'tolls_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'ehail_fee': {'': 0, -inf: 0, None: 25211, inf: 0},
'improvement_surcharge': {'': 0, -inf: 0, None: 0, inf: 0},
'total_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'payment_type': {'': 0, -inf: 0, None: 0, inf: 0},
'trip_type': {'': 0, -inf: 0, None: 0, inf: 0},
'congestion_surcharge': {'': 0, -inf: 0, None: 0, inf: 0},
'duration_min': {'': 0, -inf: 0, None: 0, inf: 0},
'prediction': {'': 0, -inf: 0, None: 0, inf: 0}},
'number_of_different_missing_values_by_column': {'VendorID': 0,
'lpep_pickup_datetime': 0,
'lpep_dropoff_datetime': 0,
'store_and_fwd_flag': 0,
'RatecodeID': 0,
'PULocationID': 0,
'DOLocationID': 0,
'passenger_count': 0,
'trip_distance': 0,
'fare_amount': 0,
'extra': 0,
'mta_tax': 0,
'tip_amount': 0,
'tolls_amount': 0,
'ehail_fee': 1,
'improvement_surcharge': 0,
'total_amount': 0,
'payment_type': 0,
'trip_type': 0,
'congestion_surcharge': 0,
'duration_min': 0,
'prediction': 0},
'number_of_missing_values': 25211,
'share_of_missing_values': 0.045454545454545456,
'number_of_missing_values_by_column': {'VendorID': 0,
'lpep_pickup_datetime': 0,
'lpep_dropoff_datetime': 0,
'store_and_fwd_flag': 0,
'RatecodeID': 0,
'PULocationID': 0,
'DOLocationID': 0,
'passenger_count': 0,
'trip_distance': 0,
'fare_amount': 0,
'extra': 0,
'mta_tax': 0,
'tip_amount': 0,
'tolls_amount': 0,
'ehail_fee': 25211,
'improvement_surcharge': 0,
'total_amount': 0,
'payment_type': 0,
'trip_type': 0,
'congestion_surcharge': 0,
'duration_min': 0,
'prediction': 0},
'share_of_missing_values_by_column': {'VendorID': 0.0,
'lpep_pickup_datetime': 0.0,
'lpep_dropoff_datetime': 0.0,
'store_and_fwd_flag': 0.0,
'RatecodeID': 0.0,
'PULocationID': 0.0,
'DOLocationID': 0.0,
'passenger_count': 0.0,
'trip_distance': 0.0,
'fare_amount': 0.0,
'extra': 0.0,
'mta_tax': 0.0,
'tip_amount': 0.0,
'tolls_amount': 0.0,
'ehail_fee': 1.0,
'improvement_surcharge': 0.0,
'total_amount': 0.0,
'payment_type': 0.0,
'trip_type': 0.0,
'congestion_surcharge': 0.0,
'duration_min': 0.0,
'prediction': 0.0},
'number_of_rows': 25211,
'number_of_rows_with_missing_values': 25211,
'share_of_rows_with_missing_values': 1.0,
'number_of_columns': 22,
'columns_with_missing_values': ['ehail_fee'],
'number_of_columns_with_missing_values': 1,
'share_of_columns_with_missing_values': 0.045454545454545456},
'reference': {'different_missing_values': {'': 0,
-inf: 0,
None: 30000,
inf: 0},
'number_of_different_missing_values': 1,
'different_missing_values_by_column': {'VendorID': {'': 0,
-inf: 0,
None: 0,
inf: 0},
'lpep_pickup_datetime': {'': 0, -inf: 0, None: 0, inf: 0},
'lpep_dropoff_datetime': {'': 0, -inf: 0, None: 0, inf: 0},
'store_and_fwd_flag': {'': 0, -inf: 0, None: 0, inf: 0},
'RatecodeID': {'': 0, -inf: 0, None: 0, inf: 0},
'PULocationID': {'': 0, -inf: 0, None: 0, inf: 0},
'DOLocationID': {'': 0, -inf: 0, None: 0, inf: 0},
'passenger_count': {'': 0, -inf: 0, None: 0, inf: 0},
'trip_distance': {'': 0, -inf: 0, None: 0, inf: 0},
'fare_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'extra': {'': 0, -inf: 0, None: 0, inf: 0},
'mta_tax': {'': 0, -inf: 0, None: 0, inf: 0},
'tip_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'tolls_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'ehail_fee': {'': 0, -inf: 0, None: 30000, inf: 0},
'improvement_surcharge': {'': 0, -inf: 0, None: 0, inf: 0},
'total_amount': {'': 0, -inf: 0, None: 0, inf: 0},
'payment_type': {'': 0, -inf: 0, None: 0, inf: 0},
'trip_type': {'': 0, -inf: 0, None: 0, inf: 0},
'congestion_surcharge': {'': 0, -inf: 0, None: 0, inf: 0},
'duration_min': {'': 0, -inf: 0, None: 0, inf: 0},
'prediction': {'': 0, -inf: 0, None: 0, inf: 0}},
'number_of_different_missing_values_by_column': {'VendorID': 0,
'lpep_pickup_datetime': 0,
'lpep_dropoff_datetime': 0,
'store_and_fwd_flag': 0,
'RatecodeID': 0,
'PULocationID': 0,
'DOLocationID': 0,
'passenger_count': 0,
'trip_distance': 0,
'fare_amount': 0,
'extra': 0,
'mta_tax': 0,
'tip_amount': 0,
'tolls_amount': 0,
'ehail_fee': 1,
'improvement_surcharge': 0,
'total_amount': 0,
'payment_type': 0,
'trip_type': 0,
'congestion_surcharge': 0,
'duration_min': 0,
'prediction': 0},
'number_of_missing_values': 30000,
'share_of_missing_values': 0.045454545454545456,
'number_of_missing_values_by_column': {'VendorID': 0,
'lpep_pickup_datetime': 0,
'lpep_dropoff_datetime': 0,
'store_and_fwd_flag': 0,
'RatecodeID': 0,
'PULocationID': 0,
'DOLocationID': 0,
'passenger_count': 0,
'trip_distance': 0,
'fare_amount': 0,
'extra': 0,
'mta_tax': 0,
'tip_amount': 0,
'tolls_amount': 0,
'ehail_fee': 30000,
'improvement_surcharge': 0,
'total_amount': 0,
'payment_type': 0,
'trip_type': 0,
'congestion_surcharge': 0,
'duration_min': 0,
'prediction': 0},
'share_of_missing_values_by_column': {'VendorID': 0.0,
'lpep_pickup_datetime': 0.0,
'lpep_dropoff_datetime': 0.0,
'store_and_fwd_flag': 0.0,
'RatecodeID': 0.0,
'PULocationID': 0.0,
'DOLocationID': 0.0,
'passenger_count': 0.0,
'trip_distance': 0.0,
'fare_amount': 0.0,
'extra': 0.0,
'mta_tax': 0.0,
'tip_amount': 0.0,
'tolls_amount': 0.0,
'ehail_fee': 1.0,
'improvement_surcharge': 0.0,
'total_amount': 0.0,
'payment_type': 0.0,
'trip_type': 0.0,
'congestion_surcharge': 0.0,
'duration_min': 0.0,
'prediction': 0.0},
'number_of_rows': 30000,
'number_of_rows_with_missing_values': 30000,
'share_of_rows_with_missing_values': 1.0,
'number_of_columns': 22,
'columns_with_missing_values': ['ehail_fee'],
'number_of_columns_with_missing_values': 1,
'share_of_columns_with_missing_values': 0.045454545454545456}}}]}In [25]python · cell 28
python
#prediction drift
result['metrics'][0]['result']['drift_score']Output
0.030493164661663727
In [26]python · cell 29
python
#number of drifted columns
result['metrics'][1]['result']['number_of_drifted_columns']Output
0
In [27]python · cell 30
python
#share of missing values
result['metrics'][2]['result']['current']['share_of_missing_values']Output
0.045454545454545456
Evidently Dashboard
In [32]python · cell 32
python
from evidently.metric_preset import DataDriftPreset, DataQualityPreset
from evidently.ui.workspace import Workspace
from evidently.ui.dashboards import DashboardPanelCounter, DashboardPanelPlot, CounterAgg, PanelValue, PlotType, ReportFilter
from evidently.renderers.html_widgets import WidgetSizeIn [30]python · cell 33
python
ws = Workspace("workspace")In [31]python · cell 34
python
project = ws.create_project("NYC Taxi Data Quality Project")
project.description = "My project descriotion"
project.save()Output
Project(id=UUID('fae27da1-1efd-4a08-82f7-ae423b64d123'), name='NYC Taxi Data Quality Project', description='My project descriotion', dashboard=DashboardConfig(name='NYC Taxi Data Quality Project', panels=[], tabs=[], tab_id_to_panel_ids={}), team_id=None, date_from=None, date_to=None)In [33]python · cell 35
python
regular_report = Report(
metrics=[
DataQualityPreset()
],
timestamp=datetime.datetime(2022,1,28)
)
regular_report.run(reference_data=None,
current_data=val_data.loc[val_data.lpep_pickup_datetime.between('2022-01-28', '2022-01-29', inclusive="left")],
column_mapping=column_mapping)
regular_reportOutput
<evidently.report.report.Report at 0x2a7cc5e50>
In [34]python · cell 36
python
ws.add_report(project.id, regular_report)In [35]python · cell 37
python
#configure the dashboard
project.dashboard.add_panel(
DashboardPanelCounter(
filter=ReportFilter(metadata_values={}, tag_values=[]),
agg=CounterAgg.NONE,
title="NYC taxi data dashboard"
)
)
project.dashboard.add_panel(
DashboardPanelPlot(
filter=ReportFilter(metadata_values={}, tag_values=[]),
title="Inference Count",
values=[
PanelValue(
metric_id="DatasetSummaryMetric",
field_path="current.number_of_rows",
legend="count"
),
],
plot_type=PlotType.BAR,
size=WidgetSize.HALF,
),
)
project.dashboard.add_panel(
DashboardPanelPlot(
filter=ReportFilter(metadata_values={}, tag_values=[]),
title="Number of Missing Values",
values=[
PanelValue(
metric_id="DatasetSummaryMetric",
field_path="current.number_of_missing_values",
legend="count"
),
],
plot_type=PlotType.LINE,
size=WidgetSize.HALF,
),
)
project.save()Output
Project(id=UUID('fae27da1-1efd-4a08-82f7-ae423b64d123'), name='NYC Taxi Data Quality Project', description='My project descriotion', dashboard=DashboardConfig(name='NYC Taxi Data Quality Project', panels=[DashboardPanelCounter(type='evidently.ui.dashboards.reports.DashboardPanelCounter', id=UUID('f86ffa03-5059-4320-8de7-efc23a227c4c'), title='NYC taxi data dashboard', filter=ReportFilter(metadata_values={}, tag_values=[], include_test_suites=False), size=<WidgetSize.FULL: 2>, agg=<CounterAgg.NONE: 'none'>, value=None, text=None), DashboardPanelPlot(type='evidently.ui.dashboards.reports.DashboardPanelPlot', id=UUID('ffdef20b-0e95-4a3a-b925-24df3a7450b3'), title='Inference Count', filter=ReportFilter(metadata_values={}, tag_values=[], include_test_suites=False), size=<WidgetSize.HALF: 1>, values=[PanelValue(field_path='current.number_of_rows', metric_id='DatasetSummaryMetric', metric_hash=None, metric_args={}, legend='count')], plot_type=<PlotType.BAR: 'bar'>), DashboardPanelPlot(type='evidently.ui.dashboards.reports.DashboardPanelPlot', id=UUID('cea314ff-a35a-44a0-b33f-65ff7cdc16c5'), title='Number of Missing Values', filter=ReportFilter(metadata_values={}, tag_values=[], include_test_suites=False), size=<WidgetSize.HALF: 1>, values=[PanelValue(field_path='current.number_of_missing_values', metric_id='DatasetSummaryMetric', metric_hash=None, metric_args={}, legend='count')], plot_type=<PlotType.LINE: 'line'>)], tabs=[], tab_id_to_panel_ids={}), team_id=None, date_from=None, date_to=None)In [36]python · cell 38
python
regular_report = Report(
metrics=[
DataQualityPreset()
],
timestamp=datetime.datetime(2022,1,29)
)
regular_report.run(reference_data=None,
current_data=val_data.loc[val_data.lpep_pickup_datetime.between('2022-01-29', '2022-01-30', inclusive="left")],
column_mapping=column_mapping)
regular_reportOutput
<evidently.report.report.Report at 0x2a77c18d0>
In [37]python · cell 39
python
ws.add_report(project.id, regular_report)In [ ]python · cell 40
python
