zoukankan      html  css  js  c++  java
  • SVM简单分类的使用 sklearn机器学习

    # sklearn 库中导入 svm 模块
    from sklearn import svm
    
    # 定义三个点和标签
    X = [[2, 0], [1, 1], [2,3]]
    y = [0, 0, 1]
    # 定义分类器,clf 意为 classifier,是分类器的传统命名
    clf = svm.SVC(kernel = 'linear')  # .SVC()就是 SVM 的方程,参数 kernel 为线性核函数
    # 训练分类器
    clf.fit(X, y)  # 调用分类器的 fit 函数建立模型(即计算出划分超平面,且所有相关属性都保存在了分类器 cls 里)
    
    # 打印分类器 clf 的一系列参数
    print (clf)
    
    # 支持向量
    print (clf.support_vectors_)
    
    # 属于支持向量的点的 index
    print (clf.support_)
    
    # 在每一个类中有多少个点属于支持向量
    print (clf.n_support_)
    
    # 预测一个新的点
    print (clf.predict([[2,0]]))
    
    SVC(C=1.0, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
        decision_function_shape='ovr', degree=3, gamma='scale', kernel='linear',
        max_iter=-1, probability=False, random_state=None, shrinking=True,
        tol=0.001, verbose=False)
    [[1. 1.]
     [2. 3.]]
    [1 2]
    [1 1]
    [0]
    

      

      

  • 相关阅读:
    codeforces 985 F. Isomorphic Strings
    Educational Codeforces Round 44
    codeforces 979D
    ARC060 Digit Sum II
    Iroha and Haiku II
    Unhappy Hacking II
    Just h-index 2018湘潭邀请赛
    [HAOI2007]理想的正方形
    P1231 教辅的组成
    最小割数学形式
  • 原文地址:https://www.cnblogs.com/LiuXinyu12378/p/13571288.html
Copyright © 2011-2022 走看看