Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active December 19, 2021 22:32
Show Gist options
  • Select an option

  • Save jayhuang75/280d4420c95eaaeb4bb2c82507271d54 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/280d4420c95eaaeb4bb2c82507271d54 to your computer and use it in GitHub Desktop.
rust-go-train-delay-ml-pipeline-trait
// Application Container
pub struct Application {
pub pipeline: Box<dyn MlPipeline>
}
// Application Interface
#[async_trait(?Send)]
pub trait MlPipeline{
async fn extract(&self) -> Result<String, AppError>;
async fn read_csv(&self, path: &Path) -> Result<PolarResult<DataFrame>, AppError>;
async fn feature_and_target(&self, df: &DataFrame) -> (PolarResult<DataFrame>,PolarResult<DataFrame>);
async fn feature_to_matrix(&self, df: &DataFrame) -> Result<DenseMatrix<f64>, AppError>;
async fn target_to_ndarray(&self, df: &DataFrame) -> Result<Vec<f64>, AppError>;
async fn k_fold_cross_validate(&self, x: &DenseMatrix<f64>, y: &Vec<f64>) -> Result<CrossValidationResult<f64>, AppError>;
async fn linear_regression_model_build(&self, x: &DenseMatrix<f64>, y: &Vec<f64>) -> Result<String, AppError>;
async fn build_dataframe(&self) -> Result<DataFrame, AppError>;
}
// PostgreSQL Strategy
#[derive(Debug)]
pub struct PgSource {
pub client: tokio_postgres::Client,
}
// Inital the Application with PostgreSQL Data Sources
let pg_source_app = app::configs::Application::new(Box::new(app::ml::pg::PgSource { client: db.client }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment