|
19 | 19 | import pandas as pd |
20 | 20 |
|
21 | 21 | import plexe |
| 22 | +from plexe import ModelBuilder |
22 | 23 | from plexe.internal.common.provider import ProviderConfig |
23 | 24 | from plexe.callbacks import MLFlowCallback |
24 | 25 |
|
25 | 26 |
|
26 | 27 | # Step 1: Define the model |
27 | 28 | # Note: for conciseness we leave the input schema empty and let plexe infer it |
28 | | -model = plexe.Model( |
29 | | - intent=( |
30 | | - "With 79 explanatory variables describing aspects of residential homes in Ames, Iowa, predict " |
31 | | - "the final price of each home. Use only linear regression and decision tree models, no ensembling. " |
32 | | - "The models must be extremely simple and quickly trainable on extremely constrained hardware." |
33 | | - ), |
34 | | - output_schema={ |
35 | | - "SalePrice": float, |
36 | | - }, |
37 | | -) |
38 | | - |
39 | | -# Step 2: Build the model using the training dataset |
40 | | -# 2B: Build the model with the dataset |
41 | | -# NOTE: In order to run this example, you will need to download the dataset from Kaggle |
42 | | -model.build( |
43 | | - datasets=[pd.read_csv("examples/datasets/house-prices-train.csv")], |
| 29 | +model = ModelBuilder( |
44 | 30 | provider=ProviderConfig( |
45 | 31 | default_provider="openai/gpt-4o", |
46 | 32 | orchestrator_provider="anthropic/claude-sonnet-4-20250514", |
|
49 | 35 | ops_provider="anthropic/claude-3-7-sonnet-20250219", |
50 | 36 | tool_provider="openai/gpt-4o", |
51 | 37 | ), |
| 38 | + verbose=False, |
| 39 | +) |
| 40 | + |
| 41 | +# Step 2: Build the model using the training dataset |
| 42 | +# 2B: Build the model with the dataset |
| 43 | +# NOTE: In order to run this example, you will need to download the dataset from Kaggle |
| 44 | +m = model.build( |
| 45 | + datasets=[pd.read_csv("examples/datasets/house-prices-train.csv")], |
| 46 | + intent=( |
| 47 | + "With 79 explanatory variables describing aspects of residential homes in Ames, Iowa, predict " |
| 48 | + "the final price of each home. Use only linear regression and decision tree models, no ensembling. " |
| 49 | + "The models must be extremely simple and quickly trainable on extremely constrained hardware." |
| 50 | + ), |
| 51 | + output_schema={ |
| 52 | + "SalePrice": float, |
| 53 | + }, |
52 | 54 | max_iterations=2, |
53 | 55 | timeout=1800, # 30 minute timeout |
54 | 56 | run_timeout=180, |
55 | | - verbose=False, |
56 | 57 | callbacks=[ |
57 | 58 | MLFlowCallback( |
58 | 59 | tracking_uri="http://127.0.0.1:8080", |
|
62 | 63 | ) |
63 | 64 |
|
64 | 65 | # Step 3: Save the model |
65 | | -plexe.save_model(model, "house-prices.tar.gz") |
| 66 | +plexe.save_model(m, "house-prices.tar.gz") |
66 | 67 |
|
67 | 68 | # Step 4: Run a prediction on the built model |
68 | 69 | test_df = pd.read_csv("examples/datasets/house-prices-test.csv").sample(10) |
69 | | -predictions = pd.DataFrame.from_records([model.predict(x) for x in test_df.to_dict(orient="records")]) |
| 70 | +predictions = pd.DataFrame.from_records([m.predict(x) for x in test_df.to_dict(orient="records")]) |
70 | 71 |
|
71 | 72 | # Step 5: print a sample of predictions |
72 | 73 | print(predictions) |
73 | 74 |
|
74 | 75 | # Step 6: Print model description |
75 | | -description = model.describe() |
| 76 | +description = m.describe() |
76 | 77 | print(description.as_text()) |
0 commit comments