SVM的python代码
时间: 2023-11-13 15:08:01 浏览: 51
SVM代码_python
4星 · 用户满意度95%
Sure, here is some sample SVM code in Python using scikit-learn library:
```
# Import required libraries
from sklearn import datasets
from sklearn import svm
# Load sample dataset
iris = datasets.load_iris()
# Create a SVM classifier
clf = svm.SVC()
# Train the classifier on the data
clf.fit(iris.data, iris.target)
# Predict the class labels for the test data
predicted = clf.predict(iris.data)
# Print the accuracy of the classifier
print("Accuracy: ", clf.score(iris.data, iris.target))
```
This code uses the Iris dataset from scikit-learn library and implements a Support Vector Machine classifier. It trains the classifier on the dataset and predicts the class labels for the test data. Finally, it prints the accuracy of the classifier. Hope this helps!
阅读全文