Skip to content

Commit d7f7646

Browse files
authored
feat: Update example (#149)
* house price * formatting
1 parent 4e76d44 commit d7f7646

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

examples/house_prices.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,14 @@
1919
import pandas as pd
2020

2121
import plexe
22+
from plexe import ModelBuilder
2223
from plexe.internal.common.provider import ProviderConfig
2324
from plexe.callbacks import MLFlowCallback
2425

2526

2627
# Step 1: Define the model
2728
# 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(
4430
provider=ProviderConfig(
4531
default_provider="openai/gpt-4o",
4632
orchestrator_provider="anthropic/claude-sonnet-4-20250514",
@@ -49,10 +35,25 @@
4935
ops_provider="anthropic/claude-3-7-sonnet-20250219",
5036
tool_provider="openai/gpt-4o",
5137
),
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+
},
5254
max_iterations=2,
5355
timeout=1800, # 30 minute timeout
5456
run_timeout=180,
55-
verbose=False,
5657
callbacks=[
5758
MLFlowCallback(
5859
tracking_uri="http://127.0.0.1:8080",
@@ -62,15 +63,15 @@
6263
)
6364

6465
# Step 3: Save the model
65-
plexe.save_model(model, "house-prices.tar.gz")
66+
plexe.save_model(m, "house-prices.tar.gz")
6667

6768
# Step 4: Run a prediction on the built model
6869
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")])
7071

7172
# Step 5: print a sample of predictions
7273
print(predictions)
7374

7475
# Step 6: Print model description
75-
description = model.describe()
76+
description = m.describe()
7677
print(description.as_text())

0 commit comments

Comments
 (0)