<jupyter_start><jupyter_text>ML1-S6 (Assignment)----  Problem 1:  SVM---- [x] Build a classification model based on SVM to classify the [Iris Dataset](https://archive.ics.uci.edu/ml/datasets/iris) , split the data to 75% training set and 25% testing set and report the training and testing accuracy .- [x] How svm can be used to solve nonlinear problems ?<jupyter_code>### Start Your Code Here ####
#First, let’s import all required libraries.
#============================================
from sklearn.svm import SVC
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.metrics import accuracy_score, confusion_matrix
from sklearn import preprocessing
from sklearn.model_selection import GridSearchCV
import warnings
warnings.filterwarnings("ignore")
import math
import operator
from sklearn.metrics import recall_score , precision_score , roc_auc_score ,roc_curve
from sklearn.datasets import load_iris
from sklearn.metrics import classification_report
from sklearn import metrics
#Loading the Data
iris= load_iris()
print("Features: ", iris.feature_names)
print("Labels: ", iris.target_names)
iris.data.shape
print(iris.target)
# Split X and Y
#======================
X= iris.data
Y= iris.target

# 75% training and 25% test
X_train, X_test, y_train, y_test= train_test_split(X, Y, test_size= 0.25,random_state=32)  
print(f'training set size: {X_train.shape[0]} samples \ntest set size: {X_test.shape[0]} samples')
# TRAIN SVM LEARNING ALGORITHM
clf = SVC(kernel = 'linear', C = 1).fit(X_train, y_train)
svm_predictions = clf.predict(X_test)
print(svm_predictions)
print("Test Score:",clf.score(X_test,y_test))
print("Train Score:",clf.score(X_train,y_train))
# Model Accuracy: how often is the classifier correct?
y_pred = clf.predict(X_test)
print("Accuracy on Test -->:",metrics.accuracy_score(y_test, y_pred))
# print(custom_model_score)
print(classification_report(y_test,y_pred))

print("-----------------------------------------------------------")
print("-----------------------------------------------------------")

x_pred = clf.predict(X_train)
print("Accuracy on Train -->  :",metrics.accuracy_score(y_train, x_pred))
# print(custom_model_score)
print(classification_report(y_train,x_pred))

cm = confusion_matrix(y_test,y_pred)
cm_df = pd.DataFrame(cm)
sns.heatmap(cm_df, annot=True)
plt.title('Accuracy using SVM:{0:.3f}'.format(accuracy_score(y_test, y_pred)))
plt.ylabel('Actual label')
plt.xlabel('Predicted label')
plt.show()
svm_ = pd.DataFrame({'Real Values':y_test, 'Predicted Values':y_pred})
svm_<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1746788990825688, 'fraction_numerical': 0.007706422018348624, 'mean_word_length': 5.098434004474273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '59723', 'license': 'MIT', 'n_tokens_mistral': 915, 'n_tokens_neox': 876, 'n_words': 233, 'path': 'SVM/ML1_S6_Assignment.ipynb', 'repo_name': 'shahd1995913/Tahalf-Mechine-Learning-DS3', 'size': '2725'}