Since the question was not very clear to begin with and attempts to explain it were going in vain, I decided to download the dataset and do it for myself. So just to make sure we are working with the same dataset iris.head() will give you or something similar, a few names might be changed and a few values, but overall strucure will be the same.

Now the first four columns are features and the fifth one is target/output.

Now you will need your X and Y as numpy arrays, to do that use

X = iris[ ['sepal length:','sepal Width:','petal length','petal width']].values
Y = iris[['Target']].values

Now since Y is categorical Data, You will need to one hot encode it using sklearn's LabelEncoder and scale the input X to do that use

label_encoder = LabelEncoder()
Y = label_encoder.fit_transform(Y)
X = StandardScaler().fit_transform(X)

To keep with the norm of separate train and test data, split the dataset using

X_train , X_test, y_train, y_test = train_test_split(X,Y)

Now just train it on your model using X_train and y_train

clf = SVC(C=1.0, kernel='rbf').fit(X_train,y_train)

After this you can use the test data to evaluate the model and tune the value of C as you wish.

Edit Just in case you don't know where the functions are here are the import statements

from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, StandardScaler
Answer from anand_v.singh on Stack Overflow
🌐
Python Programming
pythonprogramming.net › linear-svc-machine-learning-testing-data
Python Programming Tutorials
In this function, we specify two default parameters, though we could add more when we call the function. Then we call upon the key_stats.csv file to be loaded into data_df.
Discussions

python - Loading a Dataset for Linear SVM Classification from a CSV file - Stack Overflow
I have a csv file below called train.csv: 25.3, 12.4, 2.35, 4.89, 1, 2.35, 5.65, 7, 6.24, 5.52, M 20, 15.34, 8.55, 12.43, 23.5, 3, 7.6, 8.11, 4.23, 9.56, B 4.5, 2.5, 2, 5, 10, 15, 20.25, ... More on stackoverflow.com
🌐 stackoverflow.com
machine learning - How to train svm in scikit learn from training data present in a csv file - Stack Overflow
I have the training data in a CSV file whose first element is the result and the rest of the elements make the feature vector. I was using Weka to train and test various algorithms on this training More on stackoverflow.com
🌐 stackoverflow.com
java - Converting CSV file to LIBSVM compatible data file using python - Stack Overflow
I am doing a project using libsvm and I am preparing my data to use the lib. How can I convert CSV file to LIBSVM compatible data? CSV File: https://github.com/scikit-learn/scikit-learn/blob/... More on stackoverflow.com
🌐 stackoverflow.com
python - load data from csv into Scikit learn SVM - Stack Overflow
I want to train a SVM to perform a classification of samples. I have a csv file with me that has 3 columns with headers: feature 1,feature 2, class label and 20 rows(= number of samples). Now I qu... More on stackoverflow.com
🌐 stackoverflow.com
October 19, 2015
🌐
Gmu
mgta.gmu.edu › courses › ml-with-python › supportVectorMachines.php
Support Vector Machines
First create a new project in Spyder and save it as SVMClassification. Then, create a new file inside the project and save it as classification.py. You can also delete the text that's already in the file. Create a subfolder in your project called Datasets. Then download the dataset that we will be using and save it into the Datasets folder. recipes_muffins_cupcakes.csv - A CSV file containing information about petrol consumption.
🌐
GeeksforGeeks
geeksforgeeks.org › machine learning › classifying-data-using-support-vector-machinessvms-in-python
Classifying data using Support Vector Machines(SVMs) in Python - GeeksforGeeks
SVMs work best when the data has clear margins of separation, when the feature space is high-dimensional (such as text or image classification) and when datasets are moderate in size so that quadratic optimization remains feasible.
Published   August 2, 2025
🌐
Kaggle
kaggle.com › code › datacanary › svm-example
Checking your browser - reCAPTCHA
Checking your browser before accessing www.kaggle.com · Click here if you are not automatically redirected after 5 seconds
🌐
Uni-wuerzburg
biozentrum.uni-wuerzburg.de › fileadmin › 07030400 › KKaltdorf › How_to_use_the_python_script_KK_2_.pdf pdf
How to use and adapt the Python script for training of classifiers
The input csv namespaces can be separated by whitespaces or collectively read in using wildcards. ... Parameters of the classifiers can be changed in the script. The classification-functions are named svm
🌐
GitHub
gist.github.com › andreasvc › 7399482
Classify rows from CSV files with SVM with leave-one-out cross-validation; labels taken from first column, of the form 'label_description'.
Classify rows from CSV files with SVM with leave-one-out cross-validation; labels taken from first column, of the form 'label_description'. - classify.py
Find elsewhere
🌐
DatabaseTown
databasetown.com › home › machine learning › machine learning algorithms › implementing support vector machine (svm) in python
Implementing Support Vector Machine (SVM) in Python
March 14, 2023 - Now, let’s start coding in python, first, we import the important libraries such as pandas, numpy, mathplotlib, and sklearn. import pandas as pd import numpy as np from sklearn import linear_model import matplotlib.pyplot as plt ... Now we load the dataset i.e. apples_and_oranges.csv which is already placed in the same folder where svm...
🌐
Stack Abuse
stackabuse.com › implementing-svm-and-kernel-svm-with-pythons-scikit-learn
Implementing SVM and Kernel SVM with Python's Scikit-Learn
July 2, 2023 - Notice that the data is saved in a txt (text) file format, separated by commas, and it is without a header. We can reconstruct it as a table by reading it as a csv, specifying the separator as a comma, and adding the column names with the names argument.
🌐
Medium
medium.com › mlearning-ai › how-to-use-the-support-vector-machine-svm-as-a-classifier-e3b597d1b125
How to use the Support Vector Machine (SVM) as a classifier | by Crystal X | Medium
July 13, 2021 - I normally import libraries as I need them, but there are a few libraries that I customarily import at the beginning of the program, such as numpy, pandas, matplotlib and os. Numpy is a library that provides high speed algebraic calculations, Pandas creates and manipulates dataframes, matplotlib provides graphical support, and os goes into the operating system and retrieves the csv files in that directory:-
Top answer
1 of 2
7

You can use csv2libsvm.py to convert csv to libsvm data

python csv2libsvm.py iris.csv libsvm.data 4 True

where 4 means target index, and True means csv has a header.

Finally, you can get libsvm.data as

0 1:5.1 2:3.5 3:1.4 4:0.2
0 1:4.9 2:3.0 3:1.4 4:0.2
0 1:4.7 2:3.2 3:1.3 4:0.2
0 1:4.6 2:3.1 3:1.5 4:0.2
...

from iris.csv

150,4,setosa,versicolor,virginica
5.1,3.5,1.4,0.2,0
4.9,3.0,1.4,0.2,0
4.7,3.2,1.3,0.2,0
4.6,3.1,1.5,0.2,0
...
2 of 2
5

csv2libsvm.py does not work with Python3, and also it does not support label targets (string targets), I have slightly modified it. Now It should work with Python3 as well as wıth the label targets. I am very new to Python, so my code may do not follow the best practices, but I hope it is good enough to help someone.

#!/usr/bin/env python

"""
Convert CSV file to libsvm format. Works only with numeric variables.
Put -1 as label index (argv[3]) if there are no labels in your file.
Expecting no headers. If present, headers can be skipped with argv[4] == 1.

"""

import sys
import csv
import operator
from collections import defaultdict

def construct_line(label, line, labels_dict):
    new_line = []
    if label.isnumeric():
        if float(label) == 0.0:
            label = "0"
    else:
        if label in labels_dict:
            new_line.append(labels_dict.get(label))
        else:
            label_id = str(len(labels_dict))
            labels_dict[label] = label_id
            new_line.append(label_id)

    for i, item in enumerate(line):
        if item == '' or float(item) == 0.0:
            continue
        elif item=='NaN':
            item="0.0"
        new_item = "%s:%s" % (i + 1, item)
        new_line.append(new_item)
    new_line = " ".join(new_line)
    new_line += "\n"
    return new_line

# ---

input_file = sys.argv[1]
try:
    output_file = sys.argv[2]
except IndexError:
    output_file = input_file+".out"


try:
    label_index = int( sys.argv[3] )
except IndexError:
    label_index = 0

try:
    skip_headers = sys.argv[4]
except IndexError:
    skip_headers = 0

i = open(input_file, 'rt')
o = open(output_file, 'wb')

reader = csv.reader(i)

if skip_headers:
    headers = reader.__next__()

labels_dict = {}
for line in reader:
    if label_index == -1:
        label = '1'
    else:
        label = line.pop(label_index)

    new_line = construct_line(label, line, labels_dict)
    o.write(new_line.encode('utf-8'))
🌐
Stack Overflow
stackoverflow.com › questions › 30117369 › load-data-from-csv-into-scikit-learn-svm
python - load data from csv into Scikit learn SVM - Stack Overflow
October 19, 2015 - The issue was with the csv file rather than the loadtxt() function. The format in which I saved was not giving a proper .csv file(dont know why!-maybe I didnt save it at all). But there is a way to verify whether the csv file is saved in the right format or not.
🌐
Stack Overflow
stackoverflow.com › questions › 48359899 › classification-using-svm-in-python
dataset - Classification using SVM in python - Stack Overflow
import numpy from sklearn import svm import pandas as pd x = pd.read_csv('train.csv', usecols=['1.84166666681401']) y = pd.read_csv('train.csv', usecols=['2']) x=numpy.array(x) y=numpy.array(y) clf = svm.SVC(C=1,kernel="linear") clf.fit(x,y) print(clf.predict(0.7882234)) ... Warning (from warnings module): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/utils/validation.py", line 578 y = column_or_1d(y, warn=True) DataConversionWarning: A column-vector y was passed when a 1d array was expected.
🌐
scikit-learn
scikit-learn.org › stable › modules › svm.html
1.4. Support Vector Machines — scikit-learn 1.8.0 documentation
Proper choice of C and gamma is critical to the SVM’s performance. One is advised to use GridSearchCV with C and gamma spaced exponentially far apart to choose good values. ... You can define your own kernels by either giving the kernel as a python function or by precomputing the Gram matrix.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-train-an-svm-model-in-scikitlearn-python-by-input-csv-file
How to Train an SVM Model in Scikit-Learn Python by Input CSV File? | Saturn Cloud Blog
September 9, 2023 - import pandas as pd data = pd.read_csv('data.csv') Before we can train our SVM model, we need to split our data into training and testing sets.
🌐
Medium
harikabonthu96.medium.com › classification-using-svm-support-vector-machine-algorithm-289ca6081165
Classification using SVM(Support Vector Machine) Algorithm | by Harika Bonthu | Medium
June 10, 2020 - Here is how to add a file to Github repository and Read CSV data from Github · The Fish data set has 7 columns: Species, Weight, Length1, Length2, Length3, Height, Width. And our aim is to predict the ‘Species’ based on the rest of the features. Species is a categorical variable holding the values ‘Bream’, ‘Roach’, ‘Whitefish’, ‘Parkki’, ‘Perch’, ‘Pike’, ‘Smelt’. Python Code for implementing SVM: #install necessary libraries pip install pandas matplotlib seaborn sklearn#import necessary libraries import pandas as pd from sklearn.model_selection import train_tes
🌐
Analytics Vidhya
analyticsvidhya.com › home › how to use support vector machines (svm) in python and r
How to Use Support Vector Machines (SVM) in Python and R
June 16, 2025 - In this article, we’ll explore the fundamentals of SVM in machine learning, understand the algorithm, and learn how to implement SVM in Python and R for effective data classification.