# Importing all the required libraries
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, confusion_matrix
from sklearn.metrics import precision_recall_fscore_support, f1_score
from sklearn.svm import SVC
# Loading the csv that contains the sample dataset
data = pd.read_csv("apples_and_oranges.csv")
data.head()
# Seperating labels from ther dataset for sending as input to the model
y = np.array(data["Class"])
x = np.array(data.drop("Class", axis = 1))
# Doing the train and test split for evaluating the performace of the model
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 0.2
, random_state = 42)
# Doing Lbel Encoding as class column in categorical and contains textual data
# which needs to be converted to numeric form for input on to the model
le = LabelEncoder()
y = le.fit_transform(y)
np.unique(y, return_counts=True)
# Initializing the model (SVM), fitting aka training it, and then running predictions on test set
# and then finding some of the metrics for the models performance
model = SVC(C = 5)
model.fit(X_train, y_train)
preds = model.predict(X_test)
print(accuracy_score(y_test, preds), "\n")
print("confusion_matrix -\n", confusion_matrix(preds, y_test))
print("precision_recall_fscore_support -\n"
, precision_recall_fscore_support(preds, y_test))