<jupyter_start><jupyter_text>Note: SVM predicted ones and the actuals display all 9 ones, while logistic regression predicted 10 ones , but display 8 ones actuals (correct) and 2 twos actuals (incorrect).  Logistic Regression<jupyter_code>#import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn import metrics
#step1: load data
from sklearn import datasets
iris = datasets.load_iris()
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names) #inputs(4 input columns)
iris_target = iris.target
#train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris_df, iris_target, test_size=0.2)
log_reg = LogisticRegression(max_iter=1000)
log_reg.fit(X_train, y_train)
y_pred = log_reg.predict(X_test)
test_acc = metrics.accuracy_score(y_test, y_pred)
print("Testing Accuracy = ", test_acc)
# Confusion Matrix
conf_mat = metrics.confusion_matrix(y_test, y_pred)
import seaborn as sns 
#visualization library
sns.heatmap(conf_mat.T, annot=True) #annot=True is used to show the numbers in the confusion matrix
plt.xlabel("Actuals")
plt.ylabel("Predicted")
plt.show()

#precision
test_pre = metrics.precision_score(y_test, y_pred, average=None)
print("Testing Precision = ", test_pre)
#recall 
test_rec = metrics.recall_score(y_test, y_pred, average=None)
print("Testing Recall = ", test_rec)<jupyter_output><empty_output><jupyter_text>SVM<jupyter_code>#import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn import metrics
#load data
from sklearn import datasets
iris = datasets.load_iris()
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names) #inputs(4 input columns)
iris_target = iris.target
#divide data into train and test
X_train, X_test, y_train, y_test = train_test_split(iris_df, iris_target, test_size=0.2)
from sklearn import svm
svm_classifier = svm.SVC() #model svc
svm_classifier.fit(X_train, y_train) #fit it
y_pred = svm_classifier.predict(X_test)
test_acc = metrics.accuracy_score(y_test, y_pred)
print("Testing Accuracy = ", test_acc)
# Confusion Matrix
conf_mat = metrics.confusion_matrix(y_test, y_pred)
import seaborn as sns 
#visualization library
sns.heatmap(conf_mat.T, annot=True) #annot=True is used to show the numbers in the confusion matrix
plt.xlabel("Actuals")
plt.ylabel("Predicted")
plt.show()
# Precision
test_pre = metrics.precision_score(y_test, y_pred, average=None)
print("Testing Precision = ", test_pre)
#Recall 
test_rec = metrics.recall_score(y_test, y_pred, average=None)
print("Testing Recall = ", test_rec)
test_pre = metrics.precision_score(y_test, y_pred, average=None)
print("Testing Precision = ", test_pre)

test_rec = metrics.recall_score(y_test, y_pred, average=None)
print("Testing Recall = ", test_rec)<jupyter_output>Testing Precision =  [1. 1. 1.]
Testing Recall =  [1. 1. 1.]
{'fraction_non_alphanumeric': 0.0960320106702234, 'fraction_numerical': 0.007335778592864288, 'mean_word_length': 7.042895442359249, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '265385', 'license': 'MIT', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1043, 'n_words': 271, 'path': 'analytics notebook/Spot iris flower species part 2.ipynb', 'repo_name': 'miniatureengineer/mini-projects', 'size': '2999'}