// File: custom-components-preview ## CardStack ### Usage ```
| date | num1 | num2 | str1 | str2 | |
|---|---|---|---|---|---|
| 0 | 2010-01-01 00:00:00 | 0.424410 | 0.503014 | xyouzjaivrwtnqczcieb | fonxhwjxdpdvnfvtvcar |
| 1 | 2010-01-01 00:01:00 | 0.650159 | 0.184204 | dxrqtbmezgwobpqlpybt | ihahasnbtgptjfwnvlic |
| 2 | 2010-01-01 00:02:00 | 0.602216 | 0.647338 | kaatnygdfekoxmpnvbky | wffzxlyzjnopahttvdxe |
| quadkey | tile | avg_d_kbps | avg_u_kbps | avg_lat_ms | tests | devices | |
|---|---|---|---|---|---|---|---|
| 0 | 0231113112003202 | POLYGON((-90.6591796875 38.4922941923613, -90.... | 66216 | 12490 | 13 | 28 | 4 |
| 1 | 1322111021111001 | POLYGON((110.352172851562 21.2893743558604, 11... | 102598 | 37356 | 13 | 15 | 4 |
| 2 | 3112203030003110 | POLYGON((138.592529296875 -34.9219710361638, 1... | 24686 | 18736 | 18 | 162 | 106 |
| 3 | 0320000130321312 | POLYGON((-87.637939453125 40.225024210605, -87... | 17674 | 13989 | 78 | 364 | 4 |
| 4 | 0320001332313103 | POLYGON((-84.7430419921875 38.9209554204673, -... | 441192 | 218955 | 22 | 14 | 1 |
| id | feature_1 | feature_2 | feature_12 | |
|---|---|---|---|---|
| 0 | 1 | foo | fizz | foofizz |
| 1 | 2 | bar | buzz | barbuzz |
| index | id | feat_1 | feat_2 | feat_12 | |
|---|---|---|---|---|---|
| 0 | 0 | 1 | foo | fizz | foofizz |
| 1 | 1 | 2 | bar | buzz | barbuzz |
| train-mlogloss-mean | train-mlogloss-std | test-mlogloss-mean | test-mlogloss-std | |
|---|---|---|---|---|
| 0 | 0.741877 | 0.001425 | 0.750814 | 0.002562 |
| 1 | 0.533298 | 0.003306 | 0.550585 | 0.001667 |
| 2 | 0.394987 | 0.002554 | 0.421669 | 0.002304 |
| 3 | 0.300281 | 0.002392 | 0.337402 | 0.003478 |
| 4 | 0.231565 | 0.001567 | 0.280347 | 0.004483 |
| number | value | datetime_start | datetime_complete | duration | params_criterion | params_max_depth | state | |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0.926667 | 2022-06-02 20:54:48.817826 | 2022-06-02 20:54:48.861575 | 0 days 00:00:00.043749 | gini | 6 | COMPLETE |
| 1 | 1 | 0.733333 | 2022-06-02 20:54:48.861829 | 2022-06-02 20:54:48.864031 | 0 days 00:00:00.002202 | entropy | 2 | COMPLETE |
| 2 | 2 | 0.913333 | 2022-06-02 20:54:48.864197 | 2022-06-02 20:54:48.866374 | 0 days 00:00:00.002177 | gini | 10 | COMPLETE |
| 3 | 3 | 0.946667 | 2022-06-02 20:54:48.866538 | 2022-06-02 20:54:48.868643 | 0 days 00:00:00.002105 | entropy | 9 | COMPLETE |
| 4 | 4 | 0.960000 | 2022-06-02 20:54:48.868813 | 2022-06-02 20:54:48.870919 | 0 days 00:00:00.002106 | gini | 15 | COMPLETE |
| model | params | mean accuracy | std accuracy | |
|---|---|---|---|---|
| 0 | <class 'sklearn.linear_model._logistic.Logisti... | {"C": 0.5} | 0.966667 | 0.021082 |
| 1 | <class 'sklearn.linear_model._logistic.Logisti... | {"C": 1.0} | 0.973333 | 0.024944 |
| 2 | <class 'sklearn.ensemble._forest.RandomForestC... | {"max_depth": 2} | 0.960000 | 0.024944 |
| 3 | <class 'sklearn.ensemble._forest.RandomForestC... | {"max_depth": 6} | 0.960000 | 0.024944 |
Welcome to Metaflow |
Metaflow Tutorial |
Metaflow Cards |
|  |  |  |
|
A quick tour of Metaflow features - start here!
Open Sandbox
|
A simple Metaflow tutorial, as featured in the Metaflow documentation
Open Sandbox
|
Experiment with custom visualizations defined as Metaflow cards.
Open Sandbox
|
| /tmp/code-package-diffs/DBTFlow/216737/jaffle_models/133178241e4_rfi/test_yield.py | /tmp/code-package-diffs/DBTFlow/216798/jaffle_models/1332054laidzm33/test_yield.py | ||||
|---|---|---|---|---|---|
| f | 1 | import subprocess | f | 1 | import subprocess |
| 2 | 2 | ||||
| 3 | 3 | ||||
| 4 | def main(): | 4 | def main(): | ||
| 5 | print("before yield") | 5 | print("before yield") | ||
| 6 | for s in no(): | 6 | for s in no(): | ||
| 7 | print(s) | 7 | print(s) | ||
| n | 8 | subprocess.call(["echo", "TEST"]) | n | 8 | for line in subp_ret(): |
| 9 | print(line) | ||||
| 9 | for s in yes(): | 10 | for s in yes(): | ||
| 10 | print(s) | 11 | print(s) | ||
| 11 | 12 | ||||
| 12 | print("after yield") | 13 | print("after yield") | ||
| 13 | 14 | ||||
| 14 | def yes(): | 15 | def yes(): | ||
| 15 | yield "ahh" | 16 | yield "ahh" | ||
| 16 | yield "no!" | 17 | yield "no!" | ||
| 17 | yield "does this work?" | 18 | yield "does this work?" | ||
| 18 | 19 | ||||
| 19 | def no(): | 20 | def no(): | ||
| 20 | yield "no" | 21 | yield "no" | ||
| 21 | yield "say it aint so" | 22 | yield "say it aint so" | ||
| 22 | 23 | ||||
| t | t | 24 | def subp_ret(): | ||
| 25 | return subp() | ||||
| 26 | |||||
| 27 | |||||
| 28 | def subp(): | ||||
| 29 | try: | ||||
| 30 | cmd = [] | ||||
| 31 | process = subprocess.Popen( | ||||
| 32 | ["./echo.sh", "5"], | ||||
| 33 | stdout=subprocess.PIPE, | ||||
| 34 | ) | ||||
| 35 | while True: | ||||
| 36 | process.poll() | ||||
| 37 | if process.returncode is None: | ||||
| 38 | # process is still running | ||||
| 39 | line = process.stdout.readline() | ||||
| 40 | if not line: | ||||
| 41 | # end of stdout, but process has not ended yet. | ||||
| 42 | continue | ||||
| 43 | yield line.decode() | ||||
| 44 | elif process.returncode == 0: | ||||
| 45 | break | ||||
| 46 | elif process.returncode != 0: | ||||
| 47 | raise Exception("Derped") | ||||
| 48 | finally: | ||||
| 49 | pass | ||||
| 50 | |||||
| 23 | if __name__=="__main__": | 51 | if __name__=="__main__": | ||
| 24 | main() | 52 | main() | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
---
// File: data-science/welcome/how-to-index
As even seemingly simple ML projects can grow into a set of complex subtasks (such as those illustrated in the figure below), we are continuously building a library of answers to questions that many people face in their daily lives of building end-to-end ML applications.

Here you can find a growing collection of how-to guides that help you build real-life data science and machine learning applications using Metaflow.
### Data
#### Local Data
- [How to Load CSV Data in Metaflow Steps](/load-csv-in-metaflow-steps/)
- [How to Load Local Data with IncludeFile](/load-local-data-with-include/)
- [How to Run SQL Query with Pandas](/query-local-db/)
#### Cloud Data
- [How to Chunk a Dataframe to Parquet](/chunk-df/)
- [How to Load Parquet Data from S3 to Arrow Table](/load-parquet-data-to-arrow-table/)
- [How to Load Parquet Data from S3 to Pandas DataFrame](/load-parquet-data-to-pandas-df/)
- [How to Share Local Data with S3](/sharing-local-data-with-s3/)
- [How to Run SQL Query with AWS Athena](/run-sql-query-aws-athena/)
#### Core Concepts
- [Loading Tabular Data from Files](/tabular-file-formats/)
- [Python Data Structures for Tabular Data](/python-tabular-data-structures/)
### Compute
#### Configuring Remote Instances
- [How to Use and Configure Fast Bakery](/outerbounds/fast-bakery/)
- [How to Build a Custom Docker Image](/build-custom-image/)
- [How to Package Files for Remote Compute](/package-files-remote-compute/)
- [How to Use a Custom Docker Image](/use-custom-image/)
#### Performance Acceleration
- [How to Scale Model Training and Tuning to GPU](/scale-model-training-and-tuning/)
- [How to Use Multiple CPU Cores](/use-multiple-cpu-cores/)
### Orchestration
#### Flow Architecture
- [How to Access Parent Directories from a Flow](/access-parent-directories/)
- [How to Define Lists as Parameters](/define-lists-as-params/)
- [How to Use Artifacts in Metaflow Join Step](/use-artifacts-in-join-step/)
- [How to Nest Foreach Flows](/nested-foreach/)
- [How to Store Artifacts across Metaflow Steps](/pass-artifacts-between-steps/)
- [How to Set Environment Variables with .env File](/set-env-vars-with-file/)
- [How to Set Environment Variables with Metaflow Decorator](/set-env-vars-with-decorator/)
#### Iterative Flow Development
- [How to Debug Metaflow Errors with Resume](/debug-errors-with-resume/)
- [How to Handle Tasks that may Fail](/handle-tasks-that-fail/)
#### Core Concepts
- [Why Should I Care About DAGs and Workflows in Data Science?](/dags-in-data-science/)
### Versioning
#### Versioned Flows and Artifacts
- [How to Add and Remove Tags](/add-remove-tags/)
- [How to Download Metaflow Task Code Package](/download-code-package/)
- [How to Filter Flows on Condition](/filter-on-condition/)
- [How to List Flow Steps with Client API](/list-flow-steps/)
- [How to Pass XGBoost DMatrix Between Metaflow Steps](/pass-xgboost-dmatrix-between-steps/)
- [How to Whether to Use a Flow's self Keyword](/whether-to-self/)
- [How to Reuse Parameters Across Flows](/reuse-parameters-across-flows/)
#### Versioned Environments
- [How to Specify Conda Channels](/specify-conda-channels/)
- [How to Speed Up Conda](/speed-up-conda/)
- [How to Use Multiple Metaflow Configuration Files](/use-multiple-metaflow-configs/)
#### Experiment Tracking
- [How to Track Artifacts with CometML](/track-comet/)
- [How to Track Artifacts with Weights and Biases](/track-wandb/)
#### Core Concepts
- [Reproducible Machine Learning](/reproducible-ml/)
- [Versioning Code and Models](/versioning-code-and-models/)
### Deployment
#### Alerting
- [How to Email Results of a Flow](/email-flow-results/)
#### Deploying Models
- [How to Deploy with Sagemaker](/deploy-with-sagemaker/)
#### Deploying Flows
- [How to Schedule Flows on AWS Step Functions](/schedule-flow-on-step-functions/)
#### Testing
- [How to Test a Flow with PyTest](/use-pytest/)
### Modeling
#### Modeling Frameworks
- [How to Use Keras with Metaflow](/use-keras-with-metaflow/)
- [How to Use PyTorch with Metaflow](/use-pytorch-with-metaflow/)
- [How to Use Scikit-learn Estimators with Metaflow](/use-sklearn-estimators-with-metaflow/)
- [How to Use XGBoost with Metaflow](/use-xgboost-with-metaflow/)
#### Flow Design
- [How to Reuse a Model Object](/reuse-model-object/)
#### Hyperparameter Tuning
- [How to Cross-validation in Parallel](/cross-validation-in-parallel/)
- [How to Use Optuna with Metaflow](/use-optuna-with-metaflow/)
- [How to Grid Search with Metaflow](/grid-search-with-metaflow/)
#### Core Concepts
- [What is Cross-validation?](/what-is-cross-val/)
- [The Difference between Random Forests and Boosted Trees](/use-tree-model/)
---
// File: data-science/welcome/stack
How should one go about building a modern application powered by machine learning and data science? It is not easy
to give a prescriptive answer given the vast diversity of techniques and use cases involved. However, there are common, foundational components without which developing and operating a production-ready data science application would be difficult.
We can put these components together in a stack that looks like this:

The stack is organized so that the most foundational components, data and compute, are at the bottom and higher-level concerns at the top. Most production-quality applications need a solution for every layer of the stack, the implementation of which
vary depending on the application and the business environment.
Consider the stack a core mental model which helps you build and operate data-intensive applications. Each layer comes with questions and considerations of its own, which is why we have organized articles on this site after the stack, as shown on the left navigation bar.
You may wonder: Why this stack and not another one? You could label the layers differently and find another way to arrange them but the activities behind them are fundamental and rather unavoidable, as illustrated below.
## What’s behind the stack?
We want to empower a data scientist to develop applications - not just models - independently. Compare this to a modern full-stack engineer who is able to develop full-fledged websites on their own, thanks to the modern web stack.

A definining feature of data science applications is that they need _data_. The data may be tabular, stored in a data warehouse, or unstructured data like text or images. In any case, the question of data discovery and data access needs to be addressed.

Another defining feature of data science is that it involves processing data or _computation_. Machine learning in particular is a compute-heavy activity, so being able to provision enough compute capacity is crucial. Even if your data is small and models lightweight, you can benefit from parallelized computation to speed up exploration and experimentation.

A data science application consists of multiple units of computation which can be [organized as a workflow](/dags-in-data-science).
Whereas the compute layer provides raw horsepower for executing functions, it is the job of a workflow orchestrator to ensure
that the workflow gets executed reliably, on schedule, without any human intervention.

The development of a workflow happens through many iterations. Multiple variants of the project may be tested concurrently, developed by a team of data scientists working simultaneously. Tracking and organizing the work requires a robust versioning
layer that makes sure that variants don't interfere with each other and [experiments can be tracked and analyzed consistently](/versioning-code-and-models).

To produce real business value, workflows must be connected to surrounding
business systems and set up to run reliably without human intervention, that is, they must be _deployed to production_. There isn't a single way to deploy machine learning to production. Instead, different applications necessitate different deployment patterns.

Once all these layers are in place, one can start optimizing the quality and performance of models. The infrastructure stack
can be shared by a diverse set of applications and models, from basic regression to sophisticated deep learning. They
all benefit from the layers below.

## Using the stack
You can start building applications with the stack today! Making this happen requires collaboration between engineers and data
scientists: The engineers need to set up the data, compute, and orchestration layers. Fear not: Our [documentation for engineering](/engineering/welcome/) includes customizable blueprints that help you get started.
Once the foundational layers are in place, [Metaflow](https://docs.metaflow.org) wraps them in a human-friendly API, allowing
data scientists to build applications without having to get their hands dirty with the infrastructure. Metaflow comes with a built-in versioning layer, as well as patterns for robust deployments, which empower data scientists to prototype and productionize applications independently.

While the stack provides a robust scaffolding for applications, it doesn't build them by itself. It is still up to you, the
data scientist, to understand business requirements, data, modeling constraints, and patterns of deployments. This can feel
like a daunting job!
Over many years, we have helped hundreds of data scientists and engineers [on our Slack](http://slack.outerbounds.co) who
have asked a myriad of questions, some mundane and some very advanced, touching all layers of the stack. We are collecting
these questions with answers on this site, so they can benefit you during your journey.
If you need help with anything related to the stack and you can't find an answer quickly here, [join our Slack for support](http://slack.outerbounds.co)!
## See Also
[Test the stack live with a Metaflow Sandbox](/sandbox)
---
[Video: The Modern Stack for ML Infrastructure](https://www.youtube.com/watch?v=gZnhSHvhuFQ)
---
[Book: Effective Data Science Infrastructure](https://www.manning.com/books/effective-data-science-infrastructure)
---
---
// File: engineering/architecture
Metaflow can be used in _the local mode,_ e.g. on a laptop*,* without any connection to the outside world. The local mode is the default out-of-the-box when you `pip install metaflow`. In this mode, all computation is performed locally as subprocesses and all data and metadata is persisted in a local directory.
To benefit from the centralized [experiment tracking and sharing via Client API](https://docs.metaflow.org/metaflow/client), [scalable computation](https://docs.metaflow.org/metaflow/scaling-out-and-up), [dependency management](https://docs.metaflow.org/metaflow/dependencies), and [production deployments](https://docs.metaflow.org/going-to-production-with-metaflow/scheduling-metaflow-flows), we recommend that an administrator sets up infrastructure that allows Metaflow to be used in _the shared mode_.
## Shared Mode Architecture
The diagram below shows an overview of services used by Metaflow in the shared mode. The services outlined in yellow are required: Development Environment, Datastore, and Metaflow Service and its database. The services outlined with dashed lines are optional.

| date | num1 | num2 | str1 | str2 | |
|---|---|---|---|---|---|
| 0 | 2010-01-01 00:00:00 | 0.424410 | 0.503014 | xyouzjaivrwtnqczcieb | fonxhwjxdpdvnfvtvcar |
| 1 | 2010-01-01 00:01:00 | 0.650159 | 0.184204 | dxrqtbmezgwobpqlpybt | ihahasnbtgptjfwnvlic |
| 2 | 2010-01-01 00:02:00 | 0.602216 | 0.647338 | kaatnygdfekoxmpnvbky | wffzxlyzjnopahttvdxe |
| quadkey | tile | avg_d_kbps | avg_u_kbps | avg_lat_ms | tests | devices | |
|---|---|---|---|---|---|---|---|
| 0 | 0231113112003202 | POLYGON((-90.6591796875 38.4922941923613, -90.... | 66216 | 12490 | 13 | 28 | 4 |
| 1 | 1322111021111001 | POLYGON((110.352172851562 21.2893743558604, 11... | 102598 | 37356 | 13 | 15 | 4 |
| 2 | 3112203030003110 | POLYGON((138.592529296875 -34.9219710361638, 1... | 24686 | 18736 | 18 | 162 | 106 |
| 3 | 0320000130321312 | POLYGON((-87.637939453125 40.225024210605, -87... | 17674 | 13989 | 78 | 364 | 4 |
| 4 | 0320001332313103 | POLYGON((-84.7430419921875 38.9209554204673, -... | 441192 | 218955 | 22 | 14 | 1 |
| id | feature_1 | feature_2 | feature_12 | |
|---|---|---|---|---|
| 0 | 1 | foo | fizz | foofizz |
| 1 | 2 | bar | buzz | barbuzz |
| index | id | feat_1 | feat_2 | feat_12 | |
|---|---|---|---|---|---|
| 0 | 0 | 1 | foo | fizz | foofizz |
| 1 | 1 | 2 | bar | buzz | barbuzz |
| time_in_hospital | num_lab_procedures | num_procedures | |
|---|---|---|---|
| 0 | 14 | 41 | 0 |
| 1 | 2 | 30 | 0 |
| 2 | 5 | 66 | 0 |
| 3 | 3 | 63 | 0 |
| 4 | 5 | 40 | 0 |
| model | test loss | accuracy | precision at recall | |
|---|---|---|---|---|
| 0 | Baseline FFN | 0.065856 | 0.9801 | 0.991326 |
| 1 | CNN | 0.026307 | 0.9910 | 0.999272 |
| flow id | flow name | model name | test loss | accuracy | precision at recall | |
|---|---|---|---|---|---|---|
| 0 | 1666721523161525 | TuningFlow | CNN | 0.026965 | 0.9910 | 0.999272 |
| 1 | 1665967558891569 | TuningFlow | CNN | 0.027228 | 0.9907 | 0.999168 |
| 2 | 1666721393687341 | ModelComparisonFlow | CNN | 0.026307 | 0.9910 | 0.999272 |
| 3 | 1665967344088184 | ModelComparisonFlow | CNN | 0.030421 | 0.9892 | 0.998545 |
| labels | review | |
|---|---|---|
| 0 | 0 | Odd fit: I wanted to love this sweater but the... |
| 1 | 1 | Very comfy dress: The quality and material of ... |
| 2 | 0 | Fits nicely but fabric a bit thin: I ordered t... |
| 3 | 1 | Great fit: Love these jeans, fit and style... ... |
| 4 | 0 | Stretches out, washes poorly. wish i could ret... |
| row_id | user_id | artist | track | playlist | |
|---|---|---|---|---|---|
| 0 | 0 | 9cc0cfd4d7d7885102480dd99e7a90d6 | Elvis Costello | (The Angels Wanna Wear My) Red Shoes | HARD ROCK 2010 |
| 1 | 1 | 9cc0cfd4d7d7885102480dd99e7a90d6 | Elvis Costello & The Attractions | (What's So Funny 'Bout) Peace, Love And Unders... | HARD ROCK 2010 |
| 2 | 2 | 9cc0cfd4d7d7885102480dd99e7a90d6 | Tiffany Page | 7 Years Too Late | HARD ROCK 2010 |
| playlist_id | artist_sequence | track_sequence | track_test_x | track_test_y | predictions | hit | |
|---|---|---|---|---|---|---|---|
| 56437 | 69080ca9b4d90cc7c6425ccc32626df7-Arcade Fire -... | [Arcade Fire, Arcade Fire, Arcade Fire, Arcade... | [Arcade Fire|||Afterlife, Arcade Fire|||Awful ... | [Arcade Fire|||Afterlife, Arcade Fire|||Awful ... | Arcade Fire|||You Already Know | [Nick Cave & The Bad Seeds|||We No Who U R, Pa... | 0 |
| 9442 | 0a94b98aa949dbb6c9acfd78a79671e2-Double Jointed | [Mark Kozelek, Sun Kil Moon, The Flaming Lips,... | [Mark Kozelek|||Around and Around, Sun Kil Moo... | [Mark Kozelek|||Around and Around, Sun Kil Moo... | Mojave 3|||Writing to St. Peter | [Alexandre Desplat|||Mr. Fox In The Fields Med... | 0 |
| 96621 | 1954a8f3f1a377582fd9b21db7301d32-Joel | [Death Cab for Cutie, Ben Folds Five, Real Est... | [Death Cab for Cutie|||A Lack Of Color, Ben Fo... | [Death Cab for Cutie|||A Lack Of Color, Ben Fo... | Ben Folds|||Zak and Sara | [tUnE-yArDs|||You Yes You, Perfume Genius|||Yo... | 0 |