<jupyter_start><jupyter_text>Question : Use IRIS dataset from Sklearn and perform KNN. Compare with logistic regression<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn import datasets, preprocessing
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
from sklearn.preprocessing import StandardScaler
iris = datasets.load_iris()
dir(iris)
X = iris.data
y = iris.target
print(X.shape, y.shape)

X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2, random_state=49)
print(X_train.shape, X_test.shape)
print(y_train.shape, y_test.shape)
scaler = StandardScaler()
scaler.fit(X_train)
scaled_train_x = scaler.fit_transform(X_train)
scaled_test_x = scaler.fit_transform(X_test)
knn = KNeighborsClassifier(n_neighbors=5)
knn.fit(scaled_train_x, y_train)
ypred = knn.predict(scaled_test_x)
accuracy_score(y_test,ypred)
xt = confusion_matrix(y_test, ypred)
xt
sns.heatmap(cm, annot=True)
plt.show()
log_reg = LogisticRegression()
log_reg.fit(scaled_train_x,y_train)
ypred1 = log_reg.predict(scaled_test_x)
accuracy_score(y_test, ypred1)
cm1 = confusion_matrix(y_test, ypred1)
cm1
sns.heatmap(cm1, annot=True)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0882768361581921, 'fraction_numerical': 0.007768361581920904, 'mean_word_length': 8.322368421052632, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '191230', 'license': 'Apache-2.0', 'n_tokens_mistral': 543, 'n_tokens_neox': 528, 'n_words': 109, 'path': 'AIML Assignment Day 31.ipynb', 'repo_name': 'Raji-prog/LetsUpgradeAI-ML', 'size': '1416'}