536aeaeba0
Signed-off-by: Snehit Sah <snehitsah@protonmail.com>
34 lines
966 B
Python
34 lines
966 B
Python
import pandas as pd
|
|
import numpy as np
|
|
data= pd.read_csv('tren_complete_switched.csv')
|
|
X= data.iloc[:, [0,1,2]].values #All rows, all columns except the last
|
|
y= data.iloc[:, 3].values #All rows, last column (labels)
|
|
|
|
#data preprocessing
|
|
from sklearn.preprocessing import StandardScaler
|
|
scaler =StandardScaler()
|
|
X = scaler.fit_transform(X)
|
|
|
|
#training the svm model
|
|
from sklearn.svm import SVC
|
|
from sklearn.model_selection import train_test_split
|
|
from sklearn.metrics import accuracy_score
|
|
|
|
#split data into training and testing sets
|
|
X_train, X_test, y_train,y_test =train_test_split(X,y,test_size=0.3, random_state=42) #70/30 split
|
|
|
|
models = ['rbf', 'linear', 'poly', 'sigmoid']
|
|
|
|
for m in models:
|
|
#SVM classifier
|
|
model=SVC(kernel=m)
|
|
|
|
#train the model
|
|
model.fit(X_train,y_train)
|
|
|
|
#make predictions
|
|
y_pred=model.predict(X_test)
|
|
|
|
#evaluate the model
|
|
accuracy =accuracy_score(y_test,y_pred)
|
|
print(f"Accuracy: {accuracy}, Model: {m}",) |