<jupyter_start><jupyter_text>Random Tree ML<jupyter_code>!pip install sklearn<jupyter_output>Requirement already satisfied: sklearn in c:\users\ethan\anaconda3\lib\site-packages (0.0)
Requirement already satisfied: scikit-learn in c:\users\ethan\anaconda3\lib\site-packages (from sklearn) (0.22.1)
Requirement already satisfied: numpy>=1.11.0 in c:\users\ethan\anaconda3\lib\site-packages (from scikit-learn->sklearn) (1.18.1)
Requirement already satisfied: scipy>=0.17.0 in c:\users\ethan\anaconda3\lib\site-packages (from scikit-learn->sklearn) (1.4.1)
Requirement already satisfied: joblib>=0.11 in c:\users\ethan\anaconda3\lib\site-packages (from scikit-learn->sklearn) (0.14.1)<jupyter_text>that one kaggle example on card fraud<jupyter_code>import pandas as pd 
import matplotlib.pyplot as plt 
import numpy as np 
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, roc_curve, roc_auc_score, f1_score, precision_recall_curve
#from sklearn.grid_search import GridSearchCV
from sklearn.model_selection import GridSearchCV
import itertools

def plot_confusion_matrix(cm, classes,
                          normalize=False,
                          title='Confusion matrix',
                          cmap=plt.cm.Blues):
    plt.imshow(cm, interpolation='nearest', cmap=cmap)
    plt.title(title)
    plt.colorbar()
    tick_marks = np.arange(len(classes))
    plt.xticks(tick_marks, classes, rotation=45)
    plt.yticks(tick_marks, classes)

    if normalize:
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
    thresh = cm.max() / 2.
    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
        plt.text(j, i, cm[i, j],
                 horizontalalignment="center",
                 color="white" if cm[i, j] > thresh else "black")

    plt.tight_layout()
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
    plt.show()
def show_data(cm, print_res = 0):
    tp = cm[1,1]
    fn = cm[1,0]
    fp = cm[0,1]
    tn = cm[0,0]
    if print_res == 1:
        print('Precision =     {:.3f}'.format(tp/(tp+fp)))
        print('Recall (TPR) =  {:.3f}'.format(tp/(tp+fn)))
        print('Fallout (FPR) = {:.3e}'.format(fp/(fp+tn)))
    return tp/(tp+fp), tp/(tp+fn), fp/(fp+tn)
df = pd.read_csv("output.csv.txt")
#y = np.array(df.Class.tolist())     #classes: 1..fraud, 0..no fraud
#df = df.drop('Class', 1)
#X = np.array(df.as_matrix())   # features

#X_, X_test, y_, y_test = train_test_split(X, y, test_size = 0.2)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14758566978193147, 'fraction_numerical': 0.022585669781931463, 'mean_word_length': 3.5469026548672566, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '638313', 'license': 'MIT', 'n_tokens_mistral': 972, 'n_tokens_neox': 944, 'n_words': 192, 'path': 'Untitled.ipynb', 'repo_name': 'Gendo90/TVS-default-risk', 'size': '2568'}