zoukankan      html  css  js  c++  java
  • SVM简单上手示例

    转载自 百度知道 id:风_南(https://zhidao.baidu.com/usercenter?uid=e9904069236f25705e799313)

    转载只为方便学习复习,侵删。

    在用scikit-learn包训练机器学习模型时候,这里举一个训练SVM的例子:

    1. 先要按照scikit-learn包,先安装下面三个依赖包:

    Python (>= 2.6 or >= 3.3),

    NumPy (>= 1.6.1),

    SciPy (>= 0.9).

    然后在cmd命令行中输入:

    pip install  scikit-learn

    import numpy as np
    X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]]) #数据特征
    y = np.array([1, 1, 2, 2])  # 数据对应的标签
    from sklearn.svm import SVC  # 导入svm的svc类(支持向量分类)
    clf = SVC()  # 创建分类器对象
    clf.fit(X, y)  # 用训练数据拟合分类器模型
    SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
        decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',
        max_iter=-1, probability=False, random_state=None, shrinking=True,
    clf.predict([[-0.8, -1]])  # 用训练好的分类器去预测[-0.8, -1]数据的标签
    #结果 [1]
  • 相关阅读:
    POJ——T2186 Popular Cows || 洛谷——P2341 [HAOI2006]受欢迎的牛
    Tarjan缩点【模板】
    shell(1):网络配置、BATH环境和通配符
    STL
    J
    H
    G
    模板整理(二)
    B
    0-1背包问题
  • 原文地址:https://www.cnblogs.com/cpg123/p/10940798.html
Copyright © 2011-2022 走看看