LightPredict is a library that aims to build the most commonly used machine learning models without much need to write the code.
pip install lightpredict
import lazypredict
Example
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from lightpredict import LightClassifier
data = load_breast_cancer()
X = data.data
y= data.target
X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=.5,random_state =123)
lcf = LightClassifier()
lcf.fit(X_train,X_test,y_train,y_test,rounds=5,plot=True) # if plot=True, a plot will be generated comparing the accuracy of all models for easy comparison
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Classification Models β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββ³βββββββββββββββββ³βββββββββββ³ββββββββββ³ββββββββββββββββββ³βββββββββββββββ
β Model β Accuracy score β f1-score β ROC-AUC β Precision score β Recall score β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β AdaBoostClassifier β 0.9614 β 0.9697 β 0.9873 β 0.97238 β 0.96703 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β BaggingClassifier β 0.96491 β 0.97207 β 0.9885 β 0.98864 β 0.95604 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β BernoulliNB β 0.6386 β 0.77944 β 0.51648 β 0.6386 β 1.0 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β DecisionTree β 0.93333 β 0.94766 β 0.92884 β 0.95028 β 0.94505 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β ExtraTree β 0.91579 β 0.93407 β 0.90878 β 0.93407 β 0.93407 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β GaussianNB β 0.95789 β 0.96739 β 0.99323 β 0.95699 β 0.97802 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β KNeighbors β 0.93684 β 0.95135 β 0.96242 β 0.93617 β 0.96703 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β LinearSVC β 0.94035 β 0.95491 β N/A β 0.92308 β 0.98901 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β LogisticReg β 0.9614 β 0.97003 β 0.98389 β 0.96216 β 0.97802 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β LogisticReg CV β 0.97544 β 0.98082 β 0.98778 β 0.97814 β 0.98352 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β NuSVC β 0.87719 β 0.91139 β 0.96325 β 0.84507 β 0.98901 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β RandomForest β 0.97193 β 0.9779 β 0.99277 β 0.98333 β 0.97253 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β RidgeClassifier β 0.9614 β 0.97003 β 0.98389 β 0.96216 β 0.97802 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β RidgeClassifierCV β 0.97544 β 0.98082 β 0.98778 β 0.97814 β 0.98352 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β SGDClassifier β 0.81404 β 0.8729 β N/A β 0.77447 β 1.0 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β SVC β 0.9193 β 0.93931 β 0.96954 β 0.90355 β 0.97802 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β XGBoost β 0.97895 β 0.98343 β 0.99002 β 0.98889 β 0.97802 β
ββββββββββββββββββββββΌβββββββββββββββββΌβββββββββββΌββββββββββΌββββββββββββββββββΌβββββββββββββββ€
β Lightgbm β 0.97193 β 0.97802 β 0.98826 β 0.97802 β 0.97802 β
ββββββββββββββββββββββ΄βββββββββββββββββ΄βββββββββββ΄ββββββββββ΄ββββββββββββββββββ΄βββββββββββββββ
Plot
LightClassifier can also plot the roc_auc curves directly. To plot them, use the following code:
lcf.roc_auc_curves(X_train,X_test,y_train,y_test)
Plot
LightClassifier can also be used to tune for hyper-parameter tuning. It automatically tunes the hyper-parameters using Optuna and displays the best score of each model along with their best parameters. Optimization & Parameters importance plots can also be automatically generated using it. To do optimization, simply call:
lcf.optimize(X_train,X_test,y_train,y_test,trials=2) # Here, trials means no. of iterations and passing plot=True plot the graphs also.
Optimizing models...
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Optimized Models & Scores β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββ³βββββββββββββ³βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Model β Best Score β Best Params β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β AdaBoost β 0.972 β {'n_estimators': 22, 'learning_rate': β
β β β 0.7865771576419738} β
βββββββββββββββββββββΌβββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β BaggingClassifier β 0.979 β {'n_estimators': 34, 'max_samples': 82} β
βββββββββββββββββββββΌβββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Decision Tree β 0.951 β {'max_depth': 6, 'min_samples_split': 14, β
β β β 'min_weight_fraction_leaf': 0.0359737959130258, β
β β β 'min_samples_leaf': 10} β
βββββββββββββββββββββΌβββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Extra Trees β 0.944 β {'max_depth': 3} β
βββββββββββββββββββββΌβββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β KNeighbors β 0.947 β {'n_neighbors': 10} β
βββββββββββββββββββββΌβββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β RandomForest β 0.972 β {'max_depth': 4, 'n_estimators': 128, β
β β β 'min_samples_leaf': 1} β
βββββββββββββββββββββΌβββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β XGBClassifier β 0.982 β {'max_depth': 6, 'n_estimators': 101, 'learning_rate': β
β β β 0.5412564423401603, 'gamma': 0.20344958660655896, β
β β β 'subsample': 0.5885059262168062} β
βββββββββββββββββββββΌβββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LightGBM β 0.972 β {'lambda_l1': 0.07859371738975324, 'lambda_l2': β
β β β 4.299498906836946, 'num_leaves': 100, β
β β β 'feature_fraction': 0.9307795680365831, β
β β β 'bagging_fraction': 0.5941966727501499, 'bagging_freq': β
β β β 7, 'min_child_samples': 39} β
βββββββββββββββββββββ΄βββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Example
from sklearn.datasets import fetch_california_housing
from lightpredict import LightRegressor
from sklearn.model_selection import train_test_split
X, y = fetch_california_housing(return_X_y=True)
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)
lr = LightRegressor()
lr.fit(x_train, x_test, y_train, y_test)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Regression Models β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββ³βββββββββββββββββββββββββ³ββββββββββββββββββββ³ββββββββββββββββββββ
β Model β r2 score β RMSE β MAE β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β AdaBoostRegressor β 0.469 β 0.848 β 0.722 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β BaggingRegressor β 0.765 β 0.564 β 0.366 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β DecisionTreeRegressor β 0.586 β 0.748 β 0.48 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β ElasticNet β 0.42 β 0.886 β 0.681 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β ElasticNetCV β 0.263 β 0.999 β 0.56 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β ExtraTreeRegressor β 0.598 β 0.737 β 0.47 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β GradientBoostingRegressβ¦ β 0.773 β 0.554 β 0.379 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β KNeighborsRegressor β 0.144 β 1.077 β 0.831 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β Lasso β 0.283 β 0.985 β 0.773 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β LassoCV β 0.296 β 0.976 β 0.56 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β LinearRegression β 0.22 β 1.028 β 0.545 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β RandomForestRegressor β 0.793 β 0.529 β 0.343 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β Ridge β 0.22 β 1.028 β 0.545 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β RidgeCV β 0.219 β 1.028 β 0.545 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β SGDRegressor β -3.182929205105068e+29 β 656296724859260.8 β 549522059251492.2 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β SVR β -0.031 β 1.181 β 0.878 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β XGBRegressor β 0.827 β 0.484 β 0.316 β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββββββΌββββββββββββββββββββ€
β LGBMRegressor β 0.826 β 0.486 β 0.318 β
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ΄ββββββββββββββββββββ΄ββββββββββββββββββββ