src/models/train_model.py
def fit_GBC(alg, X, y, X_valid, y_valid, X_cols, printFeatureImportance=True):
    """ Fits the Gradient Boosting on the training set, evaluates the ROC AUC score on the training and validation set.
    Plots the feature importance plot.

    :param alg: Gradient Boosting Classifier model
    :param X: training set input variables
    :param y: training set target variable
    :param X_valid: validation set input variables
    :param y_valid: validation set target variable
    :param X_cols: column names
    :param printFeatureImportance: True if showing the feature importance plot
    """
    # Fit the algorithm on the data
    alg.fit(X, y)

    # Predict training set:
    y_predictions = alg.predict(X)
    y_predprob = alg.predict_proba(X)[:, 1]
    y_valid_predprob = alg.predict_proba(X_valid)[:, 1]

    # Print model report:
    print("\nModel Report")
    print("Accuracy : %.4g" % accuracy_score(y, y_predictions))
    print("AUC Score (Train): %f" % roc_auc_score(y, y_predprob))
    print("AUC Validation Score : %f" % roc_auc_score(y_valid, y_valid_predprob))

    # Print Feature Importance:
    if printFeatureImportance:
        feat_imp = pd.Series(alg.feature_importances_, X_cols).sort_values(ascending=False)
        feat_imp[:20].plot(kind='bar', title='Feature Importances', figsize=(12, 8))
        plt.ylabel('Feature Importance Score')
 Fits the Gradient Boosting on the training set, evaluates the ROC AUC score on the training and validation set.
    Plots the feature importance plot.

    :param alg: Gradient Boosting Classifier model
    :param X: training set input variables
    :param y: training set target variable
    :param X_valid: validation set input variables
    :param y_valid: validation set target variable
    :param X_cols: column names
    :param printFeatureImportance: True if showing the feature importance plot
    
Fits the Gradient Boosting on the training set, evaluates the ROC AUC score on the training and validation set.
Plots the feature importance plot.
Fits the Gradient Boosting on the training set evaluates the ROC AUC score on the training and validation set . Plots the feature importance plot .
def fit_GBC(alg, X, y, X_valid, y_valid, X_cols, printFeatureImportance=True):
    alg.fit(X, y)
    y_predictions = alg.predict(X)
    y_predprob = alg.predict_proba(X)[:, 1]
    y_valid_predprob = alg.predict_proba(X_valid)[:, 1]
    print("\nModel Report")
    print("Accuracy : %.4g" % accuracy_score(y, y_predictions))
    print("AUC Score (Train): %f" % roc_auc_score(y, y_predprob))
    print("AUC Validation Score : %f" % roc_auc_score(y_valid, y_valid_predprob))
    if printFeatureImportance:
        feat_imp = pd.Series(alg.feature_importances_, X_cols).sort_values(ascending=False)
        feat_imp[:20].plot(kind='bar', title='Feature Importances', figsize=(12, 8))
        plt.ylabel('Feature Importance Score')
def fit_GBC ( alg , X , y , X_valid , y_valid , X_cols , printFeatureImportance = True ) : alg . fit ( X , y ) y_predictions = alg . predict ( X ) y_predprob = alg . predict_proba ( X ) [ : , 1 ] y_valid_predprob = alg . predict_proba ( X_valid ) [ : , 1 ] print ( "\nModel Report" ) print ( "Accuracy : %.4g" % accuracy_score ( y , y_predictions ) ) print ( "AUC Score (Train): %f" % roc_auc_score ( y , y_predprob ) ) print ( "AUC Validation Score : %f" % roc_auc_score ( y_valid , y_valid_predprob ) ) if printFeatureImportance : feat_imp = pd . Series ( alg . feature_importances_ , X_cols ) . sort_values ( ascending = False ) feat_imp [ : 20 ] . plot ( kind = 'bar' , title = 'Feature Importances' , figsize = ( 12 , 8 ) ) plt . ylabel ( 'Feature Importance Score' )
Fits the Gradient Boosting on the training set, evaluates the ROC AUC score on the training and validation set.
Fits the Gradient Boosting on the training set evaluates the ROC AUC score on the training and validation set .
""" Fits the Gradient Boosting on the training set, evaluates the ROC AUC score on the training and validation set.
    Plots the feature importance plot.

    :param alg: Gradient Boosting Classifier model
    :param X: training set input variables
    :param y: training set target variable
    :param X_valid: validation set input variables
    :param y_valid: validation set target variable
    :param X_cols: column names
    :param printFeatureImportance: True if showing the feature importance plot
    """ # Fit the algorithm on the data # Predict training set: # Print model report: # Print Feature Importance:
alg
Gradient Boosting Classifier model
Gradient Boosting Classifier model
X
training set input variables
training set input variables
y
training set target variable
training set target variable
X_valid
validation set input variables
validation set input variables
y_valid
validation set target variable
validation set target variable
X_cols
None
printFeatureImportance
True if showing the feature importance plot
True if showing the feature importance plot