Last active
October 11, 2025 08:48
-
-
Save karan842/4cc32f9f71a5d0123336938de8e2b38c to your computer and use it in GitHub Desktop.
Sample DAG orechestrator using Prefect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from prefect import flow, task | |
| from sklearn.datasets import load_diabetes | |
| from sklearn.linear_model import LinearRegression | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.metrics import mean_squared_error | |
| import pandas as pd | |
| @task | |
| def load_data(): | |
| data = load_diabetes(as_frame=True) | |
| df = data.frame | |
| print(f"✅ Dataset loaded with shape: {df.shape}") | |
| return df | |
| @task | |
| def train_model(df: pd.DataFrame): | |
| X = df.drop(columns=["target"]) | |
| y = df["target"] | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| model = LinearRegression() | |
| model.fit(X_train, y_train) | |
| preds = model.predict(X_test) | |
| mse = mean_squared_error(y_test, preds) | |
| print(f"📉 Model trained. MSE = {mse:.3f}") | |
| return mse | |
| @task | |
| def evaluate_performance(mse: float): | |
| if mse < 3000: | |
| print(f"🎯 Great performance! MSE = {mse:.2f}") | |
| else: | |
| print(f"⚠️ Needs improvement. MSE = {mse:.2f}") | |
| @flow(name="Intro ML Orchestration Flow") | |
| def diabetes_flow(): | |
| df = load_data() | |
| mse = train_model(df) | |
| evaluate_performance(mse) | |
| if __name__ == "__main__": | |
| diabetes_flow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment