use std::env::temp_dir;
use millwright::prelude::*;
fn main() -> Result<()> {
let csv = temp_dir().join("millwright_customers.csv");
std::fs::write(
&csv,
"\
age,city,tenure,plan,churned
25,ny,2,basic,1
41,sf,40,pro,0
33,ny,12,basic,0
52,la,60,pro,0
29,sf,,basic,1
48,ny,55,pro,0
37,la,18,basic,1
60,sf,72,pro,0
",
)
.map_err(|e| millwright::Error::Backend(e.to_string()))?;
let table = Table::from_csv(&csv)?;
println!(
"loaded {:?} columns = {:?}",
table.shape(),
table.column_names()
);
let profile = Profile::of_with_target(&table, "churned")?;
print!("{}", profile.summary());
println!("alerts:");
for alert in profile.alerts() {
println!(" {alert}");
}
let report = temp_dir().join("millwright_eda.html");
profile.to_html(&report)?;
println!("wrote {}", report.display());
let train = table.into_dataset("churned")?;
let mut pipe = profile
.suggest_pipeline()
.estimator("rf", RandomForest::new().n_trees(50));
println!("pipeline (EDA-seeded + model): {:?}", pipe.step_names());
pipe.fit(&train)?;
let preds = pipe.predict(train.features())?;
println!("in-sample predictions: {preds:?}");
println!("ok — the lifecycle starts where the data does.");
Ok(())
}