def main_global(model_name):
    """Main function for the global explanations."""
    X_train_encoded, y_train, X_test_encoded, y_test, encoder = data_loading.load_encoded_data()

    print(X_train_encoded)
    print(type(X_train_encoded))

    X_test, y_test = data_loading.load_data(type="testing")
    model = model_training.load_trained_model(model_name)

    # categorical_features_indices = dataset["german_credit_dataset"]["categorical_features_indices"]
    categorical_features_names, categorical_features_indices, feature_names = data_loading.analyze_dataset()
    df_credit = data_loading.load_data(type="raw")
    df_credit = data_loading.data_preparation(df_credit)
    df_credit, categorical_encoding, categorical_encoding_label = data_loading.encoding(df_credit)

    explain_with_shap_global(X_test_encoded , model, model_name)
def main_init_xai(model_name, chosen_instance=4):
    """Prepare plots and data for the xai-dashboard"""
    X_train_encoded, y_train, X_test_encoded, y_test, encoder = data_loading.load_encoded_data()
    X_test, y_test = data_loading.load_data(type="testing")
    model = model_training.load_trained_model(model_name)

    # categorical_features_indices = dataset["german_credit_dataset"]["categorical_features_indices"]
    categorical_features_names, categorical_features_indices, feature_names = data_loading.analyze_dataset()
    df_credit = data_loading.load_data(type="raw")
    df_credit = data_loading.data_preparation(df_credit)
    df_credit, categorical_encoding, categorical_encoding_label = data_loading.encoding(df_credit)

    #explain_with_lime(X_test, model, model_name, encoder, categorical_features_indices,
    #                                      categorical_encoding, categorical_encoding_label,
    #                                       feature_names, test_instance=chosen_instance)

    explain_with_shap_global(X_train_encoded, model, model_name)
def main_local(model_name, chosen_instance=1):
    """Main function for local explanations"""
    X_train_encoded, y_train, X_test_encoded, y_test, encoder = data_loading.load_encoded_data()
    X_test, y_test = data_loading.load_data(type="testing")
    model = model_training.load_trained_model(model_name)



    categorical_features_names, categorical_features_indices, feature_names = data_loading.analyze_dataset()
    df_credit = data_loading.load_data(type="raw")
    df_credit = data_loading.data_preparation(df_credit)
    df_credit, categorical_encoding, categorical_encoding_label = data_loading.encoding(df_credit)

    explain_with_lime(X_test, model, model_name, encoder, categorical_features_indices, categorical_encoding,
                      categorical_encoding_label, feature_names, test_instance=chosen_instance)

    explain_with_shap_local(X_test_encoded, model, model_name, feature_names=X_test_encoded.columns.tolist()
                            , test_instance=chosen_instance)
Пример #4
0
    def post(self):
        reqparse_args = reqparse.RequestParser()
        reqparse_args.add_argument("chosen_instance", type=int)
        args = reqparse_args.parse_args()

        print(args["chosen_instance"])
        X_test = data_loading.load_data(type="testing")
        dataTable(X_test, chosen_instance=args["chosen_instance"])

        return "data table created successfully"
Пример #5
0
def dataTable(X_test, test_instance=10):
    """Save data table for chosen instance"""
    X_test, y_test = data_loading.load_data(type="testing")
    x_num = X_test.iloc[test_instance, :]
    data_table = pd.DataFrame(X_test.iloc[test_instance, :])
    dfi.export(data_table, PATHS["03_data_outputs"] + "_data_table.png")
Пример #6
0
from backend.util.static import PATHS, dataset, params
from backend.util.util import get_the_filenames
from backend.inference.predict import predict
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
from xgboost import plot_importance
from xgboost import XGBClassifier
import matplotlib.pyplot as plt
from backend.xai_cockpit.model_explaining import *
from backend.inference.predict import *
import dataframe_image as dfi

if __name__ == '__main__':
    s = (input("Type 'start' to initialize: "))

    initialize()
    df = load_data(type="raw")
    s
    # explore_data(df)
    data_exploration(df)

    X_train_encoded, y_train, X_test_encoded, y_test, encoder = data_loading.load_encoded_data(
    )
    # Choose a model and train it
    model, model_name = model_training.model_selection(input("Select Model: "))
    print("Trained model: ", model_name)
    X_test = data_loading.train_test_split(df)
    model = model_training.train_model(X_train_encoded, y_train, model)
    model_training.save_trained_model(model, model_name)
    print("Training score data: ")
    print(model.score(X_train_encoded, y_train))
    #good: 20, bad:35
Пример #7
0
 def get(self):
     X_train, y_train = data_loading.load_data(type="training")
     data_loading.explore_data(X_train)
     return "done"