SVM的使用python代码
时间: 2023-05-13 22:07:19 浏览: 100
Sure, here's an example of how to use SVM in Python:
```
from sklearn import svm
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
# Generate some random data
X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, random_state=42)
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Create an SVM classifier
clf = svm.SVC(kernel='linear')
# Train the classifier on the training data
clf.fit(X_train, y_train)
# Test the classifier on the testing data
accuracy = clf.score(X_test, y_test)
print("Accuracy:", accuracy)
```
This code generates some random data, splits it into training and testing sets, creates an SVM classifier with a linear kernel, trains the classifier on the training data, and tests the classifier on the testing data. The output is the accuracy of the classifier on the testing data.
阅读全文