<jupyter_start><jupyter_text><jupyter_code>!pip install scikit-learn==0.24.1<jupyter_output>Requirement already satisfied: scikit-learn==0.24.1 in /usr/local/lib/python3.6/dist-packages (0.24.1)
Requirement already satisfied: scipy>=0.19.1 in /usr/local/lib/python3.6/dist-packages (from scikit-learn==0.24.1) (1.4.1)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.6/dist-packages (from scikit-learn==0.24.1) (1.0.0)
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from scikit-learn==0.24.1) (1.19.5)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from scikit-learn==0.24.1) (2.1.0)<jupyter_text>Sklearn based network performence measure [Reference](https://scikit-learn.org/stable/modules/model_evaluation.htmlaccuracy-score)  Accuracy<jupyter_code>from sklearn.metrics import accuracy_score
y_pred = [0, 2, 1, 3]
y_true = [0, 1, 2, 3]

print(accuracy_score(y_true, y_pred))
accuracy_score(y_true, y_pred, normalize=False) #return no of correctly classifed samples<jupyter_output><empty_output><jupyter_text>In Multilabel Case<jupyter_code>import numpy as np
accuracy_score(np.array([[0, 1], [1, 1]]), np.ones((2, 2)))<jupyter_output><empty_output><jupyter_text>Balanced accuracy score<jupyter_code>from sklearn.metrics import balanced_accuracy_score
y_true = [0, 1, 0, 0, 1, 0]
y_pred = [0, 1, 0, 0, 0, 1]
balanced_accuracy_score(y_true, y_pred)<jupyter_output><empty_output><jupyter_text>Top K Accuracy Only use in latest version on sckit-learn<jupyter_code>!pip list |grep scikit
from sklearn.metrics import top_k_accuracy_score
# import sklearn.metrics.jaccard_score
import numpy as np
y_true = np.array([0, 1, 2, 2])
y_score = np.array([[0.5, 0.2, 0.2],
                    [0.3, 0.4, 0.2],
                    [0.2, 0.4, 0.3],
                    [0.7, 0.2, 0.1]])

top_k_accuracy_score(y_true, y_score, k=2)
# k =1 genralised case of top k accuracy-> accuracy
top_k_accuracy_score(y_true, y_score, k=1)
# Not normalizing gives the number of "correctly" classified samples
top_k_accuracy_score(y_true, y_score, k=2, normalize=False)<jupyter_output><empty_output><jupyter_text>Confusion matrices[Ref](http://rasbt.github.io/mlxtend/user_guide/plotting/plot_confusion_matrix/)<jupyter_code>from sklearn.metrics import confusion_matrix
y_true = [2, 0, 2, 2, 0, 1]
y_pred = [0, 0, 2, 2, 0, 2]
confusion_matrix(y_true, y_pred)
from matplotlib.pyplot as plt
cm = confusion_matrix(y_true, y_pred)
plt.imshow(cm, cmap='binary')

from mlxtend.plotting import plot_confusion_matrix
import matplotlib.pyplot as plt
import numpy as np

binary1 = np.array([[4, 1],
                   [1, 2]])

fig, ax = plot_confusion_matrix(conf_mat=binary1)
plt.show()
binary = np.array([[4, 1],
                   [1, 2]])

fig, ax = plot_confusion_matrix(conf_mat=binary,
                                show_absolute=True,
                                show_normed=True,
                                colorbar=True)
plt.show()<jupyter_output><empty_output><jupyter_text>Multi Class confusion matrices<jupyter_code>from mlxtend.plotting import plot_confusion_matrix
import matplotlib.pyplot as plt
import numpy as np

multiclass = np.array([[2, 1, 0, 0],
                       [1, 2, 0, 0],
                       [0, 0, 1, 0],
                       [0, 0, 0, 1]])

fig, ax = plot_confusion_matrix(conf_mat=multiclass,
                                colorbar=True,
                                show_absolute=False,
                                show_normed=True)
plt.show()
multiclass = np.array([[2, 1, 0, 0],
                       [1, 2, 0, 0],
                       [0, 0, 1, 0],
                       [0, 0, 0, 1]])

class_names = ['class a', 'class b', 'class c', 'class d']

fig, ax = plot_confusion_matrix(conf_mat=multiclass,
                                colorbar=True,
                                show_absolute=False,
                                show_normed=True)
plt.show()<jupyter_output><empty_output><jupyter_text>Classification report<jupyter_code>from sklearn.metrics import classification_report
y_true = [0, 1, 2, 2, 0]
y_pred = [0, 0, 2, 1, 0]
target_names = ['class 0', 'class 1', 'class 2']
print(classification_report(y_true, y_pred, target_names=target_names))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13045486030939737, 'fraction_numerical': 0.043869776033248674, 'mean_word_length': 3.2470588235294118, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 37, 'https://': 1, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '420912', 'license': 'MIT', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1572, 'n_words': 334, 'path': 'performence.ipynb', 'repo_name': 'merazlab/pytorch', 'size': '4331'}