<jupyter_start><jupyter_text>Dummy data for classification<jupyter_code>import seaborn as sns 
import matplotlib.pyplot as plt

%matplotlib inline

from sklearn.datasets import make_blobs

data, labels = make_blobs(n_features=2, centers=2,cluster_std=2,random_state=3)


plt.scatter(data[:,0], data[:,1], c = labels, cmap='coolwarm');<jupyter_output><empty_output><jupyter_text>Attempt to Classify Data<jupyter_code>#Import LinearSVC
from sklearn.svm import LinearSVC

#Create instance of Support Vector Classifier
svc = LinearSVC()

#Fit estimator to 70% of the data
svc.fit(data[:70], labels[:70])

#Predict final 30%
y_pred = svc.predict(data[70:])

#Establish true y values
y_true = labels[70:]<jupyter_output><empty_output><jupyter_text>Metrics  Precision ScoreTP - True PositivesFP - False PositivesPrecision - Accuracy of positive predictions.Precision = TP/(TP + FP)<jupyter_code>from sklearn.metrics import precision_score

print("Precision score: {}".format(precision_score(y_true,y_pred)))<jupyter_output>Precision score: 1.0<jupyter_text>Recall ScoreFN - False NegativesRecall (aka sensitivity or true positive rate): Fraction of positives That were correctly identified.Recall = TP/(TP+FN)<jupyter_code>from sklearn.metrics import recall_score

print("Recall score: {}".format(recall_score(y_true,y_pred)))<jupyter_output>Recall score: 0.9333333333333333<jupyter_text>Accuracy Score<jupyter_code>from sklearn.metrics import accuracy_score

print("Accuracy score: {}".format(accuracy_score(y_true,y_pred)))<jupyter_output>Accuracy score: 0.9666666666666667<jupyter_text>Confusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix
import pandas as pd

confusion_df = pd.DataFrame(confusion_matrix(y_true,y_pred),
             columns=["Predicted Class " + str(class_name) for class_name in [0,1]],
             index = ["Class " + str(class_name) for class_name in [0,1]])

print(confusion_df)<jupyter_output>Predicted Class 0  Predicted Class 1
Class 0                 15                  0
Class 1                  1                 14<jupyter_text>Classification Report<jupyter_code>from sklearn.metrics import classification_report

print(classification_report(y_true,y_pred))<jupyter_output>precision    recall  f1-score   support

          0       0.94      1.00      0.97        15
          1       1.00      0.93      0.97        15

avg / total       0.97      0.97      0.97        30<jupyter_text>F1 Score<jupyter_code>from sklearn.metrics import f1_score

print("F1 Score: {}".format(f1_score(y_true,y_pred)))<jupyter_output>F1 Score: 0.9655172413793104<jupyter_text>Accuracy Score<jupyter_code>from sklearn.metrics import accuracy_score

print("Accuracy score: {}".format(accuracy_score(y_true,y_pred)))<jupyter_output>Accuracy score: 0.9666666666666667<jupyter_text>Metric Curves<jupyter_code>from sklearn.metrics import precision_recall_curve

precisions,recalls, thresholds<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09704784526637258, 'fraction_numerical': 0.04852392263318629, 'mean_word_length': 5.206315789473684, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '493922', 'license': 'MIT', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1002, 'n_words': 202, 'path': 'content/sklearn/.ipynb_checkpoints/Metrics - Classification Report Breakdown (Precision, Recall, F1)-checkpoint.ipynb', 'repo_name': 'jlawman/jlawman.github.io', 'size': '2947'}