# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.metrics import log_loss
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import classification_report,confusion_matrix
from sklearn.svm import SVC
iris=pd.read_csv("/kaggle/input/iris/Iris.csv")
iris.head()
iris.tail()
iris.describe()
iris.info()
iris.isnull().sum()
"""
There are no null values in the dataset.

"""
iris['Species'].unique()
"""
There are three categories of Iris flower.
"""
iris['Species'].value_counts()
import matplotlib.pyplot as plt
plt.hist(iris['Species'],bins=10, color='purple')
import seaborn as sns
sns.swarmplot(x=iris['Species'],y=iris['SepalWidthCm'], data=iris)
sns.swarmplot(x=iris['Species'],y=iris['PetalLengthCm'], data=iris)
plt.bar(x=iris['Species'],height=iris['SepalLengthCm'], color='green')
plt.show()
sns.boxplot(x='Species',y='SepalLengthCm',data=iris);
encoder=LabelEncoder()
iris['Species']=encoder.fit_transform(iris['Species'])
iris['Species']
iris.drop('Id', axis=1, inplace=True)
X=iris.drop('Species',axis=1)
y=iris['Species']
y=iris['Species']
X_train,X_test, y_train,y_test= train_test_split(X,y, test_size=0.25, random_state=1)
X_train.head()
# Feature Scaling
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.fit_transform(X_test)
X_train.shape,X_test.shape,y_train.shape,y_test.shape
model = SVC(kernel='linear')
model.fit(X_train,y_train)

y_pred_train=model.predict(X_train)
y_pred_test=model.predict(X_test)


print("Confusion Matrix of test data: ")
print(confusion_matrix(y_pred_test,y_test))

print("Classification Report of test data: ") 
print(classification_report(y_pred_test, y_test))

print("Accuracy score of train data using SVC:" , accuracy_score(y_pred_train,y_train))
print("Accuracy score of test data using SVC: " , accuracy_score(y_pred_test, y_test))
model=LogisticRegression()
model.fit(X_train,y_train)

y_pred_train=model.predict(X_train)
y_pred_test=model.predict(X_test)

train_accuracy=np.round(accuracy_score(y_pred_train,y_train),2)
test_accuracy=np.round(accuracy_score(y_pred_test,y_test),2)

print("Accuracy score on train data using Logistic Regression is: " , train_accuracy)
print("Accuracy score on test data using Logistic Regression is: " , test_accuracy)

print("Confusion Matrix of test data: ")
print(confusion_matrix(y_pred_test,y_test))

print("Classification Report of test data: ") 
print(classification_report(y_pred_test, y_test))

print("Accuracy score on train data using Logistic Regression is: " , train_accuracy)
print("Confusion Matrix of train data: ")
print(confusion_matrix(y_pred_train,y_train))

print("Classification Report of train data: ") 
print(classification_report(y_pred_train, y_train))

print("Accuracy score on test data using Logistic Regression is: " , test_accuracy)