Plot scikit-learn (sklearn) SVM decision boundary / surface

后端 未结 2 432
臣服心动
臣服心动 2020-12-20 16:58

I am currently performing multi class SVM with linear kernel using python\'s scikit library. The sample training data and testing data are as given below:

Model dat

2条回答
  •  自闭症患者
    2020-12-20 17:42

    You can use mlxtend. It's quite clean.

    First do a pip install mlxtend, and then:

    from sklearn.svm import SVC
    import matplotlib.pyplot as plt
    from mlxtend.plotting import plot_decision_regions
    
    svm = SVC(C=0.5, kernel='linear')
    svm.fit(X, y)
    plot_decision_regions(X, y, clf=svm, legend=2)
    plt.show()
    

    Where X is a two-dimensional data matrix, and y is the associated vector of training labels.

提交回复
热议问题