SVM

作者: Recalcitrant | 来源:发表于2019-10-01 13:55 被阅读0次

    支持向量机

    一、算法原理

    二、scikit-learn SVM

    from sklearn.svm import LinearSVC
    svm_clf = LinearSVC(C=1)
    svm_clf.fit(X, y)
    

    三、鸢尾花示例

    import numpy as np
    from sklearn.pipeline import Pipeline
    from sklearn.preprocessing import StandardScaler
    from sklearn.svm import LinearSVC
    
    # 导入数据集
    from sklearn.datasets import fetch_openml
    iris = fetch_openml(name='iris')
    
    # 切分数据集
    X = iris['data'][:, 2:]
    y = (iris['target'] == 'Iris-versicolor').astype(np.float64)
    
    svm_clf = Pipeline([
        ('scalar', StandardScaler()),
        ('liner_svm', LinearSVC(C=1))
    ])
    
    # 训练模型
    svm_clf.fit(X, y)
    
    # 预测
    svm_clf.predict([[5.5, 1.7]])
    
    运行结果

    相关文章

      网友评论

        本文标题:SVM

        本文链接:https://www.haomeiwen.com/subject/qutxyctx.html