def get_density(self, df0, idx_target, plots_dnst):
        FI = tools_feature_importance.evaluate_feature_importance(
            df0, idx_target)
        best_idx = numpy.argsort(-FI['F_score'].to_numpy())
        best_features = FI['features'].to_numpy()[best_idx][:4]
        target = df0.columns[idx_target]
        df = df0[[target, best_features[0], best_features[1]]]

        df = df.dropna()
        df[target] = (df[target] <= 0).astype(int)
        df = tools_DF.hash_categoricals(df)

        for i, C in enumerate([
                classifier_LM.classifier_LM(),
                classifier_SVM.classifier_SVM(),
                classifier_RF.classifier_RF(),
                classifier_KNN.classifier_KNN()
        ]):
            ML = tools_ML_v2.ML(C, self.folder_out, self.P.dark_mode)
            ML.E2E_train_test_df(df, 0, do_pca=False)
            ML.plot_density_2d(df,
                               idx_target=0,
                               N=30,
                               filename_out='density.png')

            URL = next(tempfile._get_candidate_names()) + '.png'
            os.rename(self.folder_out + 'density.png', self.folder_out + URL)
            plots_dnst[i] = [html.Img(src=self.app.get_asset_url(URL))]

        return plots_dnst
    def get_roc(self, df0, idx_target, plots_train, plots_test):

        columns = df0.columns.to_numpy()
        target = columns[idx_target]
        df = df0.dropna()
        df[target] = (df[target] <= 0).astype(int)
        df = tools_DF.hash_categoricals(df)

        for i, C in enumerate([
                classifier_LM.classifier_LM(),
                classifier_SVM.classifier_SVM(),
                classifier_RF.classifier_RF(),
                classifier_KNN.classifier_KNN()
        ]):
            ML = tools_ML_v2.ML(C, self.folder_out, self.P.dark_mode)
            ML.E2E_train_test_df(df, idx_target, do_pca=False)

            URL = next(tempfile._get_candidate_names()) + '.png'
            os.rename(self.folder_out + 'ROC_train.png', self.folder_out + URL)
            plots_train[i] = [html.Img(src=self.app.get_asset_url(URL))]

            URL = next(tempfile._get_candidate_names()) + '.png'
            os.rename(self.folder_out + 'ROC_test.png', self.folder_out + URL)
            plots_test[i] = [html.Img(src=self.app.get_asset_url(URL))]

        return plots_train, plots_test
Esempio n. 3
0
def ex_random():
    X, Y = make_regression(n_samples=1250, n_features=3, noise=50.0)
    Y[Y <= 0] = 0
    Y[Y > 0] = 1

    C = classifier_LM.classifier_LM()
    P = tools_plot_v2.Plotter(folder_out)
    df = pd.DataFrame(data=(numpy.hstack((Y.reshape((-1, 1)), X))),columns=['target'] + ['%d' % c for c in range(X.shape[1])])
    ML = tools_ML_v2.ML(C, folder_out)
    ML.E2E_train_test_df(df,idx_target=0)
    P.pairplots_df(df, idx_target=0)

    return
Esempio n. 4
0
def ex_titanic():
    #C = classifier_KNN.classifier_KNN()
    #C = classifier_DTree.classifier_DT(folder_out=folder_out)
    #C = classifier_RF.classifier_RF()
    #C = classifier_Ada.classifier_Ada()
    C = classifier_LM.classifier_LM()
    P = tools_plot_v2.Plotter(folder_out)

    df,idx_target = pd.read_csv(folder_in+'dataset_titanic.csv', sep='\t'),0
    df.drop(labels=['alive', 'deck'], axis=1, inplace=True)

    ML = tools_ML_v2.ML(C)
    ML.E2E_train_test_df(df,idx_target=idx_target)
    P.pairplots_df(df, idx_target=idx_target)

    return
Esempio n. 5
0
def ex_train_test(X,Y):
    C = classifier_LM.classifier_LM()
    ML = tools_ML_v2.ML(C, folder_out + 'original/')
    P = tools_plot_v2.Plotter(folder_out+'original/')

    df = pd.DataFrame(data=(numpy.hstack((Y.reshape((-1, 1)), X))),columns=['target'] + ['%d' % c for c in range(X.shape[1])])
    P.pairplots_df(df, idx_target=0)
    ML.E2E_train_test_df(df,idx_target=0)


    ML = tools_ML_v2.ML(C, folder_out + 'sampled/')
    P = tools_plot_v2.Plotter(folder_out + 'sampled/')
    X_Sampled, Y_Sampled = get_SMOTE_UnderSampler(X,Y,do_debug=True)
    df_sampled = pd.DataFrame(data=(numpy.hstack((Y_Sampled.reshape((-1, 1)), X_Sampled))),columns=['target'] + ['%d' % c for c in range(X.shape[1])])
    ML.E2E_train_test_df(df_sampled, idx_target=0)
    P.pairplots_df(df_sampled, idx_target=0)

    return