Package: bluecast
BlueCastA lightweight and fast auto-ml library.
BlueCast focuses on a few model architectures (on default Xgboost
only) and a few preprocessing options (only what is
needed for Xgboost). This allows for a much faster development
cycle and a much more stable codebase while also having as few dependencies
as possible for the library. Despite being lightweight in its core BlueCast
offers high customization options for advanced users. Find
the full documentationhere.InstallationInstallation for end usersInstallation for developersGeneral usageBasic usageAdvanced usageExplanatory analysisLeakage detectionEnable cross-validationEnable even more overfitting-robust cross-validationGaining extra performanceUse multi-model blended pipelineCategorical encodingCustom training configurationCustom preprocessingCustom feature selectionCustom ML modelUsing the inbuilt ExperientTrackerUse Mlflow via custom ExperientTracker APICustom data drift checkerConvenience featuresCode qualityDocumentationKaggle competition results and example notebooksHow to contributeMetaInstallationInstallation for end usersFrom PyPI:pipinstallbluecastUsing a fresh environment with Python 3.9 or higher is recommended. We consciously
do not support Python 3.8 or lower to prevent the usage of outdated Python versions
and issues connected to it.Installation for developersClone the repository:Create a new conda environment with Python 3.9 or higherrunpip install poetryto install poetry as dependency managerrunpoetry installto install all dependenciesGeneral usageBasic usageThe module blueprints contains the main functionality of the library. The main
entry point is theBlueprintclass. It already includes needed preprocessing
(including some convenience functionality like feature type detection)
and model hyperparameter tuning.frombluecast.blueprints.castimportBlueCastautoml=BlueCast(class_problem="binary",)automl.fit(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)BlueCast has simple utilities to save and load your pipeline:frombluecast.general_utils.general_utilsimportsave_to_production,load_for_production# save pipeline including trackersave_to_production(automl,"/kaggle/working/","bluecast_cv_pipeline")# in production or for further experiments this can be loaded againautoml=load_for_production("/kaggle/working/","bluecast_cv_pipeline")Since version 0.80 BlueCast offers regression as well:frombluecast.blueprints.cast_regressionimportBlueCastRegressionautoml=BlueCast(class_problem="regression",)automl.fit(df_train,target_col="target")y_hat=automl.predict(df_val)Advanced usageExplanatory analysisBlueCast offers a simple way to get a first overview of the data:frombluecast.eda.analyseimport(bi_variate_plots,univariate_plots,plot_count_pairs,correlation_heatmap,correlation_to_target,plot_pca,plot_pca_cumulative_variance,plot_theil_u_heatmap,plot_tsne,check_unique_values,plot_null_percentage,mutual_info_to_target.plot_pie_chart,)frombluecast.preprocessing.feature_typesimportFeatureTypeDetector# Here we automatically detect the numeric columnsfeat_type_detector=FeatureTypeDetector()train_data=feat_type_detector.fit_transform_feature_types(train_data)# detect columns with a very high share of unique valuesmany_unique_cols=check_unique_values(train_data,feat_type_detector.cat_columns)# plot the percentage of Nulls for all featuresplot_pie_chart(synthetic_train_test_data[0],"categorical_feature_1",)# plot the percentage of Nulls for all featuresplot_null_percentage(train_data.loc[:,feat_type_detector.num_columns],)# show univariate plotsunivariate_plots(train_data.loc[:,feat_type_detector.num_columns],# here the target column EC1 is already included)# show bi-variate plotsbi_variate_plots(train_data.loc[:,feat_type_detector.num_columns],"EC1")# show bi-variate plotsplot_count_pairs(train,test,cat_cols=train_data.loc[:,feat_type_detector.cat_columns],)# show correlation to targetcorrelation_to_target(train_data.loc[:,feat_type_detector.num_columns])# show correlation heatmapcorrelation_heatmap(train_data.loc[:,feat_type_detector.num_columns])# show a heatmap of assocations between categorical variablestheil_matrix=plot_theil_u_heatmap(train_data,feat_type_detector.cat_columns)# show mutual information of categorical features to target# features are expected to be numerical format# class problem can be any of "binary", "multiclass" or "regression"extra_params={"random_state":30}mutual_info_to_target(train_data.loc[:,feat_type_detector.num_columns],"EC1",class_problem="binary",**extra_params)## show feature space after principal component analysisplot_pca(train_data.loc[:,feat_type_detector.num_columns],"target")## show how many components are needed to explain certain varianceplot_pca_cumulative_variance(train_data.loc[:,feat_type_detector.num_columns],"target")# show feature space after t-SNEplot_tsne(train_data.loc[:,feat_type_detector.num_columns],"target",perplexity=30,random_state=0)Leakage detectionWith big data and complex pipelines data leakage can easily sneak in.
To detect leakage BlueCast offers two functions:frombluecast.eda.data_leakage_checksimport(detect_categorical_leakage,detect_leakage_via_correlation,)# Detect leakage of numeric columns based on correlationresult=detect_leakage_via_correlation(train_data.loc[:,feat_type_detector.num_columns],"target",threshold=0.9)# Detect leakage of categorical columns based on Theil's Uresult=detect_categorical_leakage(train_data.loc[:,feat_type_detector.cat_columns],"target",threshold=0.9)Enable cross-validationWhile the default behaviour of BlueCast is to use a simple
train-test-split, cross-validation can be enabled easily:frombluecast.blueprints.castimportBlueCast
frombluecast.config.training_configimportTrainingConfig# Create a custom training config and adjust general training parameterstrain_config=TrainingConfig()train_config.hypertuning_cv_folds=5# default is 1# Pass the custom configs to the BlueCast classautoml=BlueCast(class_problem="binary",conf_training=train_config,)automl.fit(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)This will use Xgboost's inbuilt cross validation routine which allows BlueCast
to execute early pruning on not promising hyperparameter sets. This way BlueCast
can test many more hyperparameters than usual cross validation.Enable even more overfitting-robust cross-validationThere might be situations where a preprocessing step has a high risk of overfitting
and  needs even more careful evaluation (i.e. oversampling techniques). For such
scenarios BlueCast offers a solution as well.frombluecast.blueprints.castimportBlueCast
frombluecast.config.training_configimportTrainingConfig# Create a custom training config and adjust general training parameterstrain_config=TrainingConfig()train_config.hypertuning_cv_folds=5# default is 1train_config.precise_cv_tuning=True# this enables the better routine# this only makes sense if we have an overfitting risky stepcustom_preprocessor=MyCustomPreprocessing()# see section Custom Preprocessing for details# Pass the custom configs to the BlueCast classautoml=BlueCast(class_problem="binary",conf_training=train_config,custom_in_fold_preprocessor=custom_preprocessor# this happens during each fold)automl.fit(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)The custom in fold preprocessing takes place within the cross validation and
executes the step on each fold. The evaluation metric is special here:
Instead of calculating matthews correlation coefficient reversed only,
it applied increasingly random noise to the eval dataset to find an even
more robust hyperparameter set.This is much more robust, but does not offer
early pruning and is much slower. BlueCastCV supports this as well.Please note that this is an experimental feature.Gaining extra performanceBy default BlueCast uses Optuna's Bayesian hyperparameter optimization,
however Bayesian methods give an estimate and do not necessarly find
the ideal spot, thus BlueCast has an optional GridSearch setting
that allows BlueCast to refine some of the parameters Optuna has found.
This can be enabled by settingenable_grid_search_fine_tuningto True.
This fine-tuning step uses a different random seed than the autotuning
routine (seed from the settings + 1000).frombluecast.blueprints.castimportBlueCast
frombluecast.config.training_configimportTrainingConfig# Create a custom training config and adjust general training parameterstrain_config=TrainingConfig()train_config.hypertuning_cv_folds=5# default is 1train_config.enable_grid_search_fine_tuning=True# default is Falsetrain_config.gridsearch_tuning_max_runtime_secs=3600# max runtime in secstrain_config.gridsearch_nb_parameters_per_grid=5# increasing this means X^3 trials atm# Pass the custom configs to the BlueCast classautoml=BlueCast(class_problem="binary",conf_training=train_config,)automl.fit(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)This comes with a tradeoff of longer runtime. This behaviour can be further
controlled with two parameters:gridsearch_nb_parameters_per_grid: Decides how
many steps the grid shall have per parametergridsearch_tuning_max_runtime_secs: Sets the maximum time in seconds
the tuning shall run. This will finish the latest trial nd will exceed
this limit though.Use multi-model blended pipelineBy default, BlueCast trains a single model. However, it is possible to
train multiple models with one call for extra robustness.BlueCastCVhas afitand afit_evalmethod. Thefit_evalmethod trains the
models, but also provides out-of-fold validation. AlsoBlueCastCVallows to pass custom configurations.frombluecast.blueprints.cast_cvimportBlueCastCV
frombluecast.config.training_configimportTrainingConfig,XgboostTuneParamsConfig# Pass the custom configs to the BlueCast classautoml=BlueCastCV(class_problem="binary",#conf_training=train_config,#conf_xgboost=xgboost_param_config,#custom_preprocessor=custom_preprocessor, # this takes place right after test_train_split#custom_last_mile_computation=custom_last_mile_computation, # last step before model training/prediction#custom_feature_selector=custom_feature_selector,)# this class has a train method:# automl.fit(df_train, target_col="target")automl.fit_eval(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)Also here a variant for regression is available:frombluecast.blueprints.cast_cv_regressionimportBlueCastCVRegression
frombluecast.config.training_configimportTrainingConfig,XgboostTuneParamsConfig# Pass the custom configs to the BlueCast classautoml=BlueCastCVRegression(class_problem="regression",#conf_training=train_config,#conf_xgboost=xgboost_param_config,#custom_preprocessor=custom_preprocessor, # this takes place right after test_train_split#custom_last_mile_computation=custom_last_mile_computation, # last step before model training/prediction#custom_feature_selector=custom_feature_selector,)# this class has a train method:# automl.fit(df_train, target_col="target")automl.fit_eval(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)Categorical encodingBy default, BlueCast uses onehot and target encoding. An orchestrator measures the
columns' cardinality and routes each categorical column to onehot or target encoding.
Onehot encoding is applied when the cardinality is less or equalcardinality_threshold_for_onehot_encodingfrom the training config (5 by default).This behaviour can be changed in the TrainingConfig by settingcat_encoding_via_ml_algorithmto True. This will change the expectations ofcustom_last_mile_computationthough.
Ifcat_encoding_via_ml_algorithmis set to False,custom_last_mile_computationwill receive numerical features only as target encoding will apply before. Ifcat_encoding_via_ml_algorithmis True (default setting)custom_last_mile_computationwill receive categorical
features as well, because Xgboost's or a custom model's inbuilt categorical encoding
will be used.Custom training configurationDespite e2eml, BlueCast allows easy customization. Users can adjust the
configuration and just pass it to theBlueCastclass. Here is an example:frombluecast.blueprints.castimportBlueCast
frombluecast.config.training_configimportTrainingConfig,XgboostTuneParamsConfig# Create a custom tuning config and adjust hyperparameter search spacexgboost_param_config=XgboostTuneParamsConfig()xgboost_param_config.steps_max=100xgboost_param_config.max_leaves_max=16# Create a custom training config and adjust general training parameterstrain_config=TrainingConfig()train_config.hyperparameter_tuning_rounds=10train_config.autotune_model=False# we want to run just normal training, no hyperparameter tuning# We could even just overwrite the final Xgboost params using the XgboostFinalParamConfig class# Pass the custom configs to the BlueCast classautoml=BlueCast(class_problem="binary",conf_training=train_config,conf_xgboost=xgboost_param_config,)automl.fit(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)Custom preprocessingTheBlueCastclass also allows for custom preprocessing. This is done by
an abstract class that can be inherited and passed into theBlueCastclass.
BlueCast provides two entry points to inject custom preprocessing. The
attributecustom_preprocessoris called right after the train_test_split.
The attributecustom_last_mile_computationwill be called before the model
training or prediction starts (when only numerical features are present anymore)
and allows users to execute last computations (i.e. sub sampling or final calculations).frombluecast.blueprints.castimportBlueCast
frombluecast.preprocessing.customimportCustomPreprocessing# Create a custom tuning config and adjust hyperparameter search spacexgboost_param_config=XgboostTuneParamsConfig()xgboost_param_config.steps_max=100xgboost_param_config.max_leaves_max=16# Create a custom training config and adjust general training parameterstrain_config=TrainingConfig()train_config.hyperparameter_tuning_rounds=10train_config.autotune_model=False# we want to run just normal training, no hyperparameter tuning# We could even just overwrite the final Xgboost params using the XgboostFinalParamConfig classclassMyCustomPreprocessing(CustomPreprocessing):def__init__(self):self.trained_patterns={}deffit_transform(self,df:pd.DataFrame,target:pd.Series)->Tuple[pd.DataFrame,pd.Series]:num_columns=df.drop(['Beta','Gamma','Delta','Alpha','EJ'],axis=1).columnscat_df=df[['Beta','Gamma','Delta','Alpha','EJ']].copy()zscores=Zscores()zscores.fit_all(df,['Beta','Gamma','Delta','Alpha','EJ'])df=zscores.transform_all(df,['Beta','Gamma','Delta','Alpha','EJ'])self.trained_patterns["zscores"]=zscoresimp_mean=SimpleImputer(missing_values=np.nan,strategy='median')num_columns=df.drop(['Beta','Gamma','Delta','Alpha','EJ'],axis=1).columnsimp_mean.fit(df.loc[:,num_columns])df=imp_mean.transform(df.loc[:,num_columns])self.trained_patterns["imputation"]=imp_meandf=pd.DataFrame(df,columns=num_columns).merge(cat_df,left_index=True,right_index=True,how="left")df=df.drop(['Beta','Gamma','Delta','Alpha'],axis=1)returndf,targetdeftransform(self,df:pd.DataFrame,target:Optional[pd.Series]=None,predicton_mode:bool=False,)->Tuple[pd.DataFrame,Optional[pd.Series]]:num_columns=df.drop(['Beta','Gamma','Delta','Alpha','EJ'],axis=1).columnscat_df=df[['Beta','Gamma','Delta','Alpha','EJ']].copy()df=self.trained_patterns["zscores"].transform_all(df,['Beta','Gamma','Delta','Alpha','EJ'])imp_mean=self.trained_patterns["imputation"]num_columns=df.drop(['Beta','Gamma','Delta','Alpha','EJ'],axis=1).columnsdf.loc[:,num_columns]=df.loc[:,num_columns].replace([np.inf,-np.inf],np.nan)df=imp_mean.transform(df.loc[:,num_columns])df=pd.DataFrame(df,columns=num_columns).merge(cat_df,left_index=True,right_index=True,how="left")df=df.drop(['Beta','Gamma','Delta','Alpha'],axis=1)returndf,target# add custom last mile computationclassMyCustomLastMilePreprocessing(CustomPreprocessing):defcustom_function(self,df:pd.DataFrame)->pd.DataFrame:df=df/2df["custom_col"]=5returndf# Please note: The base class enforces that the fit_transform method is implementeddeffit_transform(self,df:pd.DataFrame,target:pd.Series)->Tuple[pd.DataFrame,pd.Series]:df=self.custom_function(df)df=df.head(1000)target=target.head(1000)returndf,target# Please note: The base class enforces that the fit_transform method is implementeddeftransform(self,df:pd.DataFrame,target:Optional[pd.Series]=None,predicton_mode:bool=False,)->Tuple[pd.DataFrame,Optional[pd.Series]]:df=self.custom_function(df)ifnotpredicton_modeandisinstance(target,pd.Series):df=df.head(100)target=target.head(100)returndf,targecustom_last_mile_computation=MyCustomLastMilePreprocessing()custom_preprocessor=MyCustomPreprocessing()# Pass the custom configs to the BlueCast classautoml=BlueCast(class_problem="binary",conf_training=train_config,conf_xgboost=xgboost_param_config,custom_preprocessor=custom_preprocessor,# this takes place right after test_train_splitcustom_last_mile_computation=custom_last_mile_computation,# last step before model training/prediction)automl.fit(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)Custom feature selectionBlueCast offers automated feature selection. On default the feature
selection is disabled, but BlueCast raises a warning to inform the
user about this option. The behaviour can be controlled via theTrainingConfig.frombluecast.blueprints.castimportBlueCast
frombluecast.preprocessing.customimportCustomPreprocessing
frombluecast.config.training_configimportTrainingConfig# Create a custom training config and adjust general training parameterstrain_config=TrainingConfig()train_config.hyperparameter_tuning_rounds=10train_config.autotune_model=False# we want to run just normal training, no hyperparameter tuningtrain_config.enable_feature_selection=True# Pass the custom configs to the BlueCast classautoml=BlueCast(class_problem="binary",conf_training=train_config,)automl.fit(df_train,target_col="target")y_probs,y_classes=automl.predict(df_val)Also this step can be customized. The following example shows how to:frombluecast.config.training_configimportTrainingConfig
frombluecast.preprocessing.customimportCustomPreprocessing
fromsklearn.feature_selectionimportRFECV
fromsklearn.metricsimportmake_scorer,matthews_corrcoef
fromsklearn.model_selectionimportStratifiedKFold
fromtypingimportOptional,Tuple# Create a custom training config and adjust general training parameterstrain_config=TrainingConfig()train_config.enable_feature_selection=True# add custom feature selectionclassRFECVSelector(CustomPreprocessing):def__init__(self,random_state:int=0):super().__init__()self.selected_features=Noneself.random_state=random_stateself.selection_strategy:RFECV=RFECV(estimator=xgb.XGBClassifier(),step=1,cv=StratifiedKFold(5,random_state=random_state,shuffle=True),min_features_to_select=1,scoring=make_scorer(matthews_corrcoef),n_jobs=2,)deffit_transform(self,df:pd.DataFrame,target:pd.Series)->Tuple[pd.DataFrame,Optional[pd.Series]]:self.selection_strategy.fit(df,target)self.selected_features=self.selection_strategy.support_df=df.loc[:,self.selected_features]returndf,targetdeftransform(self,df:pd.DataFrame,target:Optional[pd.Series]=None,predicton_mode:bool=False)->Tuple[pd.DataFrame,Optional[pd.Series]]:df=df.loc[:,self.selected_features]returndf,targetcustom_feature_selector=RFECVSelector()# Create an instance of the BlueCast class with the custom modelbluecast=BlueCast(class_problem="binary",conf_feature_selection=custom_feat_sel,conf_training=train_config,custom_feature_selector=custom_feature_selector,# Create some sample data for testingx_train=pd.DataFrame({"feature1":[iforiinrange(10)],"feature2":[iforiinrange(10)]})y_train=pd.Series([0,1,0,1,0,1,0,1,0,1])x_test=pd.DataFrame({"feature1":[iforiinrange(10)],"feature2":[iforiinrange(10)]}x_train["target"]=y_trai# Fit the BlueCast model using the custom modelbluecast.fit(x_train,"target"# Predict on the test data using the custom modelpredicted_probas,predicted_classes=bluecast.predict(x_test)Custom ML modelFor some users it might just be convenient to use the BlueCast class to
enjoy convenience features (details see below), but use a custom ML model.
This is possible by passing a custom model to the BlueCast class. The needed properties
are defined via the BaseClassMlModel class. Here is an example:frombluecast.ml_modelling.base_classesimport(BaseClassMlModel,PredictedClasses,# just for linting checksPredictedProbas,# just for linting checks)classCustomModel(BaseClassMlModel):def__init__(self):self.model=Nonedeffit(self,x_train:pd.DataFrame,x_test:pd.DataFrame,y_train:pd.Series,y_test:pd.Series,)->None:self.model=LogisticRegression()self.model.fit(x_train,y_train)# if you wih to track experiments using an own ExperimentTracker add it here# or in the fit method itselfdefpredict(self,df:pd.DataFrame)->Tuple[PredictedProbas,PredictedClasses]:predicted_probas=self.model.predict_proba(df)predicted_classes=self.model.predict(df)returnpredicted_probas,predicted_classescustom_model=CustomModel()# Create an instance of the BlueCast class with the custom modelbluecast=BlueCast(class_problem="binary",ml_model=custom_model,# Create some sample data for testingx_train=pd.DataFrame({"feature1":[iforiinrange(10)],"feature2":[iforiinrange(10)]})y_train=pd.Series([0,1,0,1,0,1,0,1,0,1])x_test=pd.DataFrame({"feature1":[iforiinrange(10)],"feature2":[iforiinrange(10)]}x_train["target"]=y_trai# Fit the BlueCast model using the custom modelbluecast.fit(x_train,"target")# Predict on the test data using the custom modelpredicted_probas,predicted_classes=bluecast.predict(x_test)Please note that custom ML models require user defined hyperparameter tuning. Pre-defined
configurations are not available for custom models.
Also note that the calculation of SHAP values only works with tree based models by
default. For other model architectures disable SHAP values in the TrainingConfig
via:train_config.calculate_shap_values = TrueJust instantiate a new instance of the TrainingConfig, update the param as above
and pass the config as an argument to the BlueCast instance during instantiation.
Feature importance can be added in the custom model definition.Using the inbuilt ExperientTrackerFor experimentation environments it can be useful to store all variables
and results from model runs.
BlueCast has an inbuilt experiment tracker to enhance the provided insights.
No setup is required. BlueCast will automatically store all necessary data
after each hyperparameter tuning trial.# instantiate and train BlueCastfrombluecast.blueprints.castimportBlueCastautoml=BlueCast(class_problem="binary",)automl.fit_eval(df_train,df_eval,y_eval,target_col="target")# access the experiment trackertracker=automl.experiment_tracker# see all stored information as a Pandas DataFrametracker_df=tracker.retrieve_results_as_df()Now from here you could even feed selected columns back into a BlueCast
instance and try to predict the eval_score to check the get the feature
importance of your experiment data! Maybe you uncover hidden patterns
for your model training.Please note that the number of stored experiments will probably be lower
than the number of started hyperparameter tuning trials. The experiment tracker
is skipped whenever Optuna prunes a trial.
The experiment triggers whenever thefitorfit_evalmethods of a BlueCast
class instance are called (also within BlueCastCV). This means for custom
models the tracker will not trigger automatically and has to be added manually.Use Mlflow via custom ExperientTracker APIThe inbuilt experiment tracker is handy to start with, however in production
environments it might be required to send metrics to a Mlflow server or
comparable solutions. BlueCast allows to pass a custom experiment tracker.# instantiate and train BlueCastfrombluecast.blueprints.castimportBlueCast
frombluecast.cnfig.base_classesimportBaseClassExperimentTracker

classCustomExperimentTracker(BaseClassExperimentTracker):"""Base class for the experiment tracker.Enforces the implementation of the add_results and retrieve_results_as_df methods."""@abstractmethoddefadd_results(self,experiment_id:int,score_category:Literal["simple_train_test_score","cv_score","oof_score"],training_config:TrainingConfig,model_parameters:Dict[Any,Any],eval_scores:Union[float,int,None],metric_used:str,metric_higher_is_better:bool,)->None:"""Add results to the ExperimentTracker class."""pass# add Mlflow tracking i.e.@abstractmethoddefretrieve_results_as_df(self)->pd.DataFrame:"""Retrieve results from the ExperimentTracker class"""passexperiment_tracker=CustomExperimentTracker()automl=BlueCast(class_problem="binary",experiment_tracker=experiment_tracker,)automl.fit_eval(df_train,df_eval,y_eval,target_col="target")# access the experiment trackertracker=automl.experiment_tracker# see all stored information as a Pandas DataFrametracker_df=tracker.retrieve_results_as_df()Custom data drift checkerSince version 0.90 BlueCast checks for data drift for numerical
and categorical columns. The checks happen on the raw data.
Categories will be stored anonymized by default. Data drift
checks are not part of the model pipeline, but have to be called separately:frombluecast.monitoring.data_monitoringimportDataDriftdata_drift_checker=DataDrift()# statistical data drift checks for numerical featuresdata_drift_checker.kolmogorov_smirnov_test(data,new_data,threshold=0.05)# show flagsprint(data_drift_checker.kolmogorov_smirnov_flags)# statistical data drift checks for categorical featuresdata_drift_checker.population_stability_index(data,new_data)# show flagsprint(data_drift_checker.population_stability_index_flags)# show psi valuesprint(data_drift_checker.population_stability_index_values)# QQplot for two numerical columnsdata_drift_checker.qqplot_two_samples(train["feature1"],test["feature1"],x_label="X",y_label="Y")Convenience featuresDespite being a lightweight library, BlueCast also includes some convenience
with the following features:automatic feature type detection and castingautomatic DataFrame schema detection: checks if unseen data has new or
missing columnscategorical feature encoding (target encoding or directly in Xgboost)datetime feature encodingautomated GPU availability check and usage for Xgboost
a fit_eval method to fit a model and evaluate it on a validation set
to mimic production environment realityfunctions to save and load a trained pipelineshapley valuesROC AUC curve & lift chartwarnings for potential misconfigurationsThe fit_eval method can be used like this:frombluecast.blueprints.castimportBlueCastautoml=BlueCast(class_problem="binary",)automl.fit_eval(df_train,df_eval,y_eval,target_col="target")y_probs,y_classes=automl.predict(df_val)It is important to note that df_train contains the target column while
df_eval does not. The target column is passed separately as y_eval.Code qualityTo ensure code quality, we use the following tools:various pre-commit librariesstrong type hinting in the code baseunit tests using PytestFor contributors, it is expected that all pre-commit and unit tests pass.
For new features it is expected that unit tests are added.DocumentationDocumentation is provided viaRead the DocsKaggle competition results and example notebooksEven though BlueCast has been designed to be a lightweight
automl framework, it still offers the possibilities to
reach very good performance. We tested BlueCast in Kaggle
competitions to showcase the libraries capabilities
feature- and performance-wise.ICR top 20% finish with over 6000 participants (notebook)An advanced example covering lots of functionalities (notebook)PS3E23: Predict software defects top 12% finish (notebook)PS3E25: Predict hardness of steel via regression (notebook)PS4E1: Bank churn top 13% finish (notebook)How to contributeContributions are welcome. Please follow the following steps:Create a new branch from develop branchAdd your feature or fixAdd unit tests for new featuresRun pre-commit checks and unit tests (using Pytest)Adjust thedocs/source/index.mdfileCopy paste the content of thedocs/source/index.mdfile into theREADME.mdfilePush your changes and create a pull requestIf library or dev dependencies have to be changed, adjust the pyproject.toml.
For readthedocs it is also requited to update thedocs/srtd_requirements.txtfile. Simply run:poetryexport--withdev-frequirements.txt--outputdocs/rtd_requirements.txtIf readthedocs will be able to create the documentation can be tested via:poetryrunsphinx-autobuilddocs/sourcedocs/build/htmlThis will show a localhost link containing the documentation.MetaCreator: Thomas Meißner –LinkedIn