Skip to content

Commit 24ec051

Browse files
ronellecaguioaThe Meridian Authors
authored andcommitted
Document MMM schema.
PiperOrigin-RevId: 786067236
1 parent deacfa5 commit 24ec051

File tree

84 files changed

+22887
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+22887
-3
lines changed

meridian/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
# limitations under the License.
1414

1515
"""Meridian API."""
16+
1617
from meridian import analysis
1718
from meridian import data
1819
from meridian import model
1920
from meridian.version import __version__
2021

22+
2123
try:
2224
from meridian import mlflow # pylint: disable=g-import-not-at-top
2325
except ImportError:

proto/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# About MMM Proto Schema
2+
3+
The MMM Proto Schema is a framework-agnostic data standard that provides a
4+
consistent and serializable way to represent a trained Marketing Mix Model
5+
(MMM). Its core purpose is to establish a common language for the outputs of an
6+
MMM, primarily within its current Python-centric implementation. This allows the
7+
results from models built using various tools or methodologies to be uniformly
8+
represented, stored, shared, and compared by Python-based applications and
9+
workflows. By offering this standardized representation, the schema aims to
10+
enhance interoperability and facilitate downstream applications, such as scenario
11+
planning, optimization, and consistent reporting, independent of how the original
12+
model was constructed.
13+
14+
## Install Meridian with MMM Proto Schema
15+
Currently, this package can only be installed from source code:
16+
```sh
17+
git clone https://github.com/google/meridian.git;
18+
cd meridian;
19+
pip install .[schema];
20+
```

proto/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2025 The Meridian Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Module for MMM Proto Schema."""
16+
17+
__version__ = "1.0.0"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2025 The Meridian Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
edition = "2023";
16+
17+
package mmm.v1.common;
18+
19+
import "google/type/date.proto";
20+
21+
option features.field_presence = IMPLICIT;
22+
option java_multiple_files = true;
23+
24+
message DateInterval {
25+
// The start date of the interval. Inclusive. Required.
26+
google.type.Date start_date = 1;
27+
28+
// The end date of the interval. Exclusive. Required.
29+
google.type.Date end_date = 2;
30+
31+
// A tag to identify the date interval. Optional.
32+
string tag = 3;
33+
}

proto/mmm/v1/common/estimate.proto

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2025 The Meridian Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
edition = "2023";
16+
17+
package mmm.v1.common;
18+
19+
option features.field_presence = IMPLICIT;
20+
option java_multiple_files = true;
21+
22+
// Contains an estimate value of estimand and associated quantified
23+
// uncertainties.
24+
message Estimate {
25+
// The estimate value of an estimand. Required.
26+
double value = 1;
27+
28+
// The uncertainty of an estimate quantified by probability interval.
29+
message Uncertainty {
30+
// The probability that a value is inside an interval bounded by lowerbound
31+
// and upperbound. Required.
32+
double probability = 1;
33+
34+
// The lowerbound of the interval. Required.
35+
double lowerbound = 2;
36+
37+
// The upperbound of the interval. Required.
38+
double upperbound = 3;
39+
}
40+
41+
// The quantified uncertainties.
42+
repeated Uncertainty uncertainties = 2;
43+
}

proto/mmm/v1/common/kpi_type.proto

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 The Meridian Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
edition = "2023";
16+
17+
package mmm.v1.common;
18+
19+
option java_multiple_files = true;
20+
21+
// Different KPI types used in marketing performance and optimization.
22+
enum KpiType {
23+
KPI_TYPE_UNSPECIFIED = 0;
24+
25+
// Some generic user-defined KPI unit.
26+
NON_REVENUE = 1;
27+
28+
// KPI defined as revenue specifically, or some KPI unit after conversion
29+
// to revenue.
30+
REVENUE = 2;
31+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2025 The Meridian Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
edition = "2023";
16+
17+
package mmm.v1.common;
18+
19+
option java_multiple_files = true;
20+
21+
// Target metrics for marketing performance optimizations.
22+
// Note that each of these metric variants can be interpreted in terms of either
23+
// revenue or non-revenue KPI _type_. See: `common.KpiType`.
24+
enum TargetMetric {
25+
TARGET_METRIC_UNSPECIFIED = 0;
26+
27+
// Any KPI type (revenue if the model data can be converted to revenue, or
28+
// some generic KPI otherwise).
29+
KPI = 1;
30+
31+
// ROI = net KPI change / spend.
32+
ROI = 2;
33+
34+
// Marginal ROI is defined at channel level and is applied across all
35+
// channels.
36+
// mROI = changed in incremental KPI / spend.
37+
MARGINAL_ROI = 3;
38+
39+
// CPIK = total spend / change in incremental KPI.
40+
COST_PER_INCREMENTAL_KPI = 4;
41+
}

proto/mmm/v1/fit/model_fit.proto

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2025 The Meridian Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
edition = "2023";
16+
17+
package mmm.v1.fit;
18+
19+
import "mmm/v1/common/date_interval.proto";
20+
import "mmm/v1/common/estimate.proto";
21+
22+
option features.field_presence = IMPLICIT;
23+
option java_multiple_files = true;
24+
25+
// A prediction contains the predicted KPI and the ground truth at a specific
26+
// time.
27+
message Prediction {
28+
// The time associated to this prediction point. Required.
29+
common.DateInterval date_interval = 1;
30+
31+
// The predicted outcome. Required.
32+
common.Estimate predicted_outcome = 2;
33+
34+
// The predicted baseline. Optional.
35+
common.Estimate predicted_baseline = 3;
36+
37+
// The actual value observed in the data. Required.
38+
double actual_value = 4;
39+
}
40+
41+
// The model fit performance indicated by different metrics.
42+
message Performance {
43+
double r_squared = 1;
44+
45+
// Mean absolute percentage error.
46+
double mape = 2;
47+
48+
// Is equal to sum_i(actual_i - pred_i) / sum_i(actual_i)
49+
double weighted_mape = 3;
50+
51+
// Root mean square error.
52+
double rmse = 4;
53+
}
54+
55+
message Result {
56+
// The name of the result. Required.
57+
string name = 1;
58+
59+
// The predictions over different times. Required.
60+
repeated Prediction predictions = 2;
61+
62+
// The performance of the model fit. Required.
63+
Performance performance = 3;
64+
}
65+
66+
message ModelFit {
67+
// Different results for different purposes. For example, one could divide a
68+
// data to training set, testing set, and validation set. Required.
69+
repeated Result results = 1;
70+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2025 The Meridian Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
edition = "2023";
16+
17+
package mmm.v1.marketing.analysis;
18+
19+
import "mmm/v1/common/estimate.proto";
20+
import "mmm/v1/common/kpi_type.proto";
21+
22+
option features.field_presence = IMPLICIT;
23+
option java_multiple_files = true;
24+
25+
// A contribution is defined as the value difference caused by adding a new
26+
// outcome.
27+
message Contribution {
28+
// The contribution value. Required.
29+
common.Estimate value = 1;
30+
31+
// Share of contribution = contribution / total contribution from all
32+
// outcomes.
33+
common.Estimate share = 2;
34+
}
35+
36+
// Effectiveness calculates how much incremental KPI is generated per media unit
37+
// (e.g. impressions or clicks), i.e. contribution / media unit.
38+
message Effectiveness {
39+
// The media unit of the effectiveness. Required.
40+
string media_unit = 1;
41+
42+
// The value of the effectiveness. Required.
43+
common.Estimate value = 2;
44+
}
45+
46+
// An outcome analysis on KPI which can be defined as revenue or other generic
47+
// non-revenue type.
48+
message KpiOutcome {
49+
// The type of this KPI (i.e. REVENUE or NON_REVENUE)
50+
// Note that a model input with non-revenue (generic KPI) data can still have
51+
// revenue-based KPI outcomes defined, provided that `revenue_per_kpi` is
52+
// defined.
53+
common.KpiType kpi_type = 1;
54+
55+
// The contribution to a KPI.
56+
// If `kpi_type == REVENUE`, this is the revenue KPI value.
57+
// If `kpi_type == NON_REVENUE`, AND there is a `revenue_per_kpi` conversion,
58+
// this is the derived `kpi * revenue_per_kpi` value.
59+
// Otherwise, this is simply the (non-revenue, user-defined) KPI value.
60+
Contribution contribution = 2;
61+
62+
// The effectiveness of this outcome.
63+
Effectiveness effectiveness = 3;
64+
65+
// ROI = contribution / spend.
66+
// See contribution definition above.
67+
common.Estimate roi = 4;
68+
69+
// Marginal ROI shows the additional ROI gained from additional spend.
70+
// See ROI definition above.
71+
common.Estimate marginal_roi = 5;
72+
73+
// Cost per incremental outcome (which could be revenue or some generic KPI).
74+
// E.g. when contribution is thousand impression, it is CPM; when contribution
75+
// is acquisition, this is CPA.
76+
common.Estimate cost_per_contribution = 6;
77+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2025 The Meridian Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
edition = "2023";
16+
17+
package mmm.v1.marketing.analysis;
18+
19+
import "mmm/v1/common/date_interval.proto";
20+
import "mmm/v1/marketing/analysis/media_analysis.proto";
21+
import "mmm/v1/marketing/analysis/non_media_analysis.proto";
22+
23+
option java_multiple_files = true;
24+
25+
// The marketing analysis.
26+
message MarketingAnalysis {
27+
// The date interval that the analysis covers. Required.
28+
common.DateInterval date_interval = 1;
29+
30+
// Analysis on different media channels. Required.
31+
repeated MediaAnalysis media_analyses = 2;
32+
33+
// Analysis on different non-media factors.
34+
repeated NonMediaAnalysis non_media_analyses = 3;
35+
}
36+
37+
// A list of marketing analyses.
38+
message MarketingAnalysisList {
39+
// The marketing analyses for different time ranges. Required.
40+
repeated MarketingAnalysis marketing_analyses = 1;
41+
}

0 commit comments

Comments
 (0)