<jupyter_start><jupyter_text>Classification with Plain SVM<jupyter_code>from skimage.transform import resize
from skimage.io import imread

# Path to folder containing the datasets
inputPaths = "C://Users//<NAME>//Documents//7th Sem//IRC//IRC-Rover-Files//Datasets//Creating Datasets//Downloaded Datasets//Final Datasets for Training"

# All possible labels/ directions
labels = []

# List to store the paths of all images in the dataset
imagePaths = list(paths.list_images(inputPaths))

# This list will be used to store all the images in Bitmap format from OpenCV's imread()
images = []

i = 0
for imagePath in imagePaths:
    label = imagePath.split(os.path.sep)[-2]
    labels.append(label)
    
    image = cv2.imread(imagePath)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    image = cv2.resize(image, (64, 64))
    print("Added image: ", i)
    i += 1
    
    images.append(image.flatten())
print("Number of images: ", len(images))
print("Number of labels: ", len(labels))
images = np.array(images)
labels = np.array(labels)

df = pd.DataFrame(images)
df['Labels'] = labels

x = df.iloc[:, : -1]
y = df.iloc[:, -1]
# SVM Model Construction

from sklearn import svm
from sklearn.model_selection import GridSearchCV, train_test_split

# Initializing model
svc = svm.SVC(probability = True)
params = {'C' : [0.1, 1, 10, 100], 'gamma' : [0.0001, 0.01, 0.1, 1], 'kernel' : ['rbf', 'poly']}
model = GridSearchCV(svc, params)

# Split the train and test datasets
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, stratify = y)
model.fit(x_train, y_train)
# Test the trained model

y_pred = model.predict(x_test)
print("Actual:\n", y_test)
print("Predicted:\n", y_pred)

print("Accuracy: ", (accuracy_score(y_pred, y_test) * 100), "%\n\n")
# Saving the model

import pickle

fileName = "arrowClassifier.sav"
modelPath = "C://Users//<NAME>//Documents//7th Sem//IRC//IRC-Rover-Files//Saved Models//Arrow Classifier//SVM Model"
os.chdir(modelPath)

pickle.dump(model, open(filename, 'wb'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14599609375, 'fraction_numerical': 0.01953125, 'mean_word_length': 4.493297587131368, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '168852', 'license': 'MIT', 'n_tokens_mistral': 761, 'n_tokens_neox': 733, 'n_words': 190, 'path': 'Arrow Classification.ipynb', 'repo_name': 'newb-dev-1008/IRC-Rover-Files', 'size': '2056'}