# Import necessary libraries
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import classification_report, accuracy_score
# Load a dataset (e.g., Iris dataset)
iris = datasets.load_iris()
X = iris.data
y = iris.target
# Split the dataset into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Standardize features by removing the mean and scaling to unit variance
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Create an SVM classifier with a linear kernel
svm_classifier = SVC(kernel='linear')
# Fit the SVM model to the training data
svm_classifier.fit(X_train, y_train)
# Predict the labels of the test set
y_pred = svm_classifier.predict(X_test)
# Evaluate the model's performance
print("Accuracy:", accuracy_score(y_test, y_pred))
print("\nClassification Report:\n", classification_report(y_test, y_pred))
This code will print the accuracy and the classification report, which includes precision, recall, and F1-score for each class in the Iris dataset. You may need to install the scikit-learn library if you haven't already (pip install scikit-learn).