YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
import pandas as pd from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestRegressor from sklearn.preprocessing import OneHotEncoder from sklearn.compose import ColumnTransformer from sklearn.pipeline import Pipeline
Example dataset
data = pd.DataFrame({ "Project_Type": ["Residential", "Commercial", "Residential", "Road"], "Area_m2": [120, 500, 200, 2000], "Location": ["Urban", "Urban", "Rural", "Rural"], "Material_Quality": ["Medium", "High", "Low", "Low"], "Cost_USD": [40000, 250000, 60000, 300000] })
Features and target
X = data.drop("Cost_USD", axis=1) y = data["Cost_USD"]
Categorical + numeric columns
categorical = ["Project_Type", "Location", "Material_Quality"] numeric = ["Area_m2"]
preprocessor = ColumnTransformer([ ("cat", OneHotEncoder(), categorical), ("num", "passthrough", numeric) ])
Model pipeline
model = Pipeline([ ("preprocessor", preprocessor), ("regressor", RandomForestRegressor(n_estimators=100, random_state=42)) ])
Train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) model.fit(X_train, y_train)
Test prediction
print("Predicted cost:", model.predict(X_test))