This package is designed to support classification & regression modeling pipelines
install.packages("devtools")
devtools::install_github("xxxxxi0001/xxml")automate_data_cleaning— One step outlier & NA treatment based on distribution & portion of NA
-
check_na_zero()— Detect NA / Zero in all numeric variables -
replace_zero_with_na()— Convert designated zero values to NA -
median_imputation()— Impute NA using median -
z_score_outlier()— Replace outliers using z-score capping -
IQR_outlier()— IQR capping for skewed variables -
check_multicollinearity()— Detect high correlations -
automation_knn_imputation()— one-step knn imputationinitialize_distance_find_best_k()initialize_not_na_index()initialize_test_k_index()find_best_k()kNN_Imputation()
three_set_partition()— stratified train/test/validation splitensemble_train_partition()— partitions for bag ensemble
check_class_imbalance()- check if class imbalance occur
k_fold_stratified()- stratified train index into k fold for pipeline testingcross_validation()- cross validation support rf, c5, rpart, lr
backward_p_lr()— iterative removal of non-significant predictors
make_ensemble_predict_categorical()— mean probability ensemblefind_best_threshold()— threshold tuning for F1ensemble_weight_F1()— model weights from F1 performanceemsemble_result_with_weight_categorical()— weighted ensemble prediction
check_model_performance()- TPR, TNR, F1, Accuracy
generate_stack_df()- helper funcstack_model_lr()- generate new model with exsiting model with lrstack_model_predict_lr()- use stack model make prediction
three_set_partition_no_target()— randomly partitioned index into designated portionensemble_train_partition_no_target()— randomly partitioned train index into designated portion
backward_p_mlr()- iterative removal of non-significant predictors
reverse_num()- if feature changed in feature transformation, change it backmake_ensemble_predict_numerical()- use ensemble model make mean predictionensemble_weight_with_RMSE()- calculate each model's weight based on RMSEensemble_result_with_weight_numerical()- final prediction with weight
create_stack_model_mlr()- generate a new multi-linear regression model based on existing modelstack_test_mlr()- check how stack model perform
library(xxml)df <- read.csv("your_data.csv")check_na_zero(df)df <- replace_zero_with_na(df, ignore_cols = "Oldpeak")df <- automate_data_cleaning(df)df_LR$doubleRISK<-df_LR$MaxHR * df_LR$Oldpeak
df_LR$Age_square<-(df_LR$Age)^2
hist(df_LR$Age_square,prob=TRUE, main="Histogram of Age After", xlab="Age")
lines(density(df_LR$Age_square, na.rm=TRUE))
variables<-df_LR[,c("Age_square","RestingBP","Cholesterol","MaxHR","Oldpeak_square","doubleRISK_sqrt")]
check_multicollinearity(variables)
pca_results<-prcomp(df_LR[,c("Age_square","RestingBP","Cholesterol","MaxHR","Oldpeak_square","doubleRISK_sqrt")])
summary(pca_results)
pca_df<-as.data.frame(pca_results$x[,1:5])index <- three_set_partition(df, "HeartDisease", 0.5, 0.25, 1, 0)
train_index <- index$train_index
test_index <- index$test_index
val_index <- index$validation_indexlog_models <- backward_p_lr(df, train_index, "HeartDisease", 1, 1, 1)pred <- make_ensemble_predict(log_models, df, test_index, positive = 1)check_model_performance(pred, 0.5, 1, 0, df, test_index, "HeartDisease")best_threshold<-find_best_threshold(ensemble_predictions,df_encoded_LR,test_index,"HeartDisease",1,0)
weight_list<-ensemble_weight_F1(logistic_model_list,df_encoded_LR,test_index,best_threshold,"HeartDisease",1,0)
ensemble_predictions_val<-ensemble_result_with_weight(logistic_model_list,df_encoded_LR,validation_index,weight_list,1)
result_ensemble<-check_model_performance(ensemble_predictions_val,best_threshold,1,0,df_encoded_LR,validation_index,"HeartDisease")library(xxml)df <- read.csv("your_data.csv")check_na_zero(df)df <- replace_zero_with_na(df, ignore_cols = "Oldpeak")df <- automate_data_cleaning(df)df$DONATION_AMT_log<-log(df$DONATION_AMT)
hist(df$DONATION_AMT_log,prob=TRUE, main="Histogram of Donation Amount After", xlab="Donor Age")
lines(density(df$DONATION_AMT_log, na.rm=TRUE))
variables<-df[,c("DONATION_AMT_log","DONOR_AGE","INCOME_LEVEL","SES","MEDIAN_HOME_VALUE_log","MEDIAN_HOUSEHOLD_INCOME_sqrt","DONATION_RESPONSE_sqrt1","MONTHS_SINCE_LAST_GIFT_square","EMAILS_12_log","LIFETIME_GIFT_COUNT_sqrt","LIFETIME_EMAILS_sqrt","LIFETIME_GIFT_AMOUNT_sqrt","LIFETIME_MAX_GIFT_AMT_sqrt","LIFETIME_MIN_GIFT_AMT_sqrt","LIFETIME_AVG_GIFT_AMT_sqrt")]
check_multicollinearity(variables)
df_scaled[col_numeric]<-scale(df[col_numeric==TRUE])
onehot_features<-model.matrix(~URBANICITY+DONOR_GENDER+HOME_OWNER,data=df_scaled)
onehot_df<-as.data.frame(onehot_features)[,-1]set.seed(888)
partition_result<-three_set_partition_no_target(df_encoded,0.5,0.25)
train_index<-partition_result$train_index
test_index<-partition_result$test_index
validation_index<-partition_result$validation_indexmlr_list<-backward_p_mlr(df_encoded,train_partition_index,"DONATION_AMT_log")weight_list<-ensemble_weight_RMSE(mlr_list,df_encoded,test_index,"DONATION_AMT_log","log")
prediction<-emsemble_result_with_weight(mlr_list,df_encoded,validation_index,weight_list,"log")real_value<-exp(df_encoded[["DONATION_AMT_log"]][validation_index])
rmse<-sqrt(mean((real_value-prediction)^2))
correlation<-cor(prediction,real_value)
plot(prediction,real_value)
abline(0,1, col=2)stack_model<-create_stack_model_mlr(df_encoded,"DONATION_AMT_log",test_index,mlr_list)
result<-stack_test_mlr(stack_model,mlr_list,df_encoded,validation_index,"DONATION_AMT_log","log")prediction_value<-result$prediction_value
true_value<-result$true_value
correlation<-cor(prediction_value,true_value)
plot(prediction_value,true_value)
abline(0,1, col=2)