<jupyter_start><jupyter_text>Open-Source Amalgamation and Single-Product Formats AmalgamationThe simplest form of export is "amalgamation" ... in which case the model and all necessary code to run are emitted as one big chunk.In some cases, it's a single source code file that can be compiled on nearly any platform as a standalone program.  * Classic amalgamation: MXNet + model code https://mxnet.apache.org/api/faq/smart_deviceIn other cases, it's a chunk of consumable IR code that can be consumed in a common runtime:  * H2O POJO export https://github.com/h2oai/h2o-3/blob/master/h2o-docs/src/product/productionizing.rstpojo-quick-start    And sometimes ... it's a coder implementing a model by hand and compiling it! (For simple, popular models, like linear/logistic regression, it's pretty easy once you have the model params.)  What Does this Look Like? Let's Try It...First, we need a model. So we'll train a quick linear regression on R's Diamonds dataset:<jupyter_code>import pandas as pd

data = pd.read_csv('data/diamonds.csv')

X = data.carat
y = data.price
from sklearn.linear_model import LinearRegression

model = LinearRegression().fit(X.values.reshape(-1,1), y)<jupyter_output><empty_output><jupyter_text>This is a basic model for predicting price (in dollars) from weight (in carats).The params are:<jupyter_code>model.coef_, model.intercept_<jupyter_output><empty_output><jupyter_text>We can create a standalone ("amalgamated") version of this model using [SKompiler](https://pypi.org/project/SKompiler/)<jupyter_code>from skompiler import skompile

expr = skompile(model.predict)
expr.to('sqlalchemy/postgresql')
expr.to('sympy/c')<jupyter_output><empty_output><jupyter_text>Here's a quick example with a decision tree. First, we'll create the model.<jupyter_code>from sklearn.tree import DecisionTreeRegressor

model_tree = DecisionTreeRegressor(max_depth=4).fit(X.values.reshape(-1,1), y)
for line in skompile(model_tree.predict).to('sympy/c').split('\n'):
    print(line)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10069101678183613, 'fraction_numerical': 0.004935834155972359, 'mean_word_length': 5.711920529801325, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '614274', 'license': 'Apache-2.0', 'n_tokens_mistral': 666, 'n_tokens_neox': 630, 'n_words': 201, 'path': '02-OSS-Amalgamation-and-Single-Product.ipynb', 'repo_name': 'adbreind/open-standard-models-2019', 'size': '2026'}