Loading…
DS · Classification · Program 18 · In the record
Support Vector Machine (SVM) classification.
1from sklearn.datasets import load_iris2from sklearn.model_selection import train_test_split3from sklearn.svm import SVC4from sklearn.metrics import accuracy_score5 6X, y = load_iris(return_X_y=True)7X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)8 9for kernel in ['linear', 'poly', 'rbf']:10 svm = SVC(kernel=kernel).fit(X_train, y_train)11 print(f"SVM ({kernel}) Accuracy:", accuracy_score(y_test, svm.predict(X_test)))SVM (linear) Accuracy: 1.0 SVM (poly) Accuracy: 0.9777777777777777 SVM (rbf) Accuracy: 1.0

Run program 18 in your browser
Python 3.14 · Pyodide. Change the code or the input, run it, break it, and see what happens.