关于 SVM 一些疑问 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
shuangxunian
V2EX    程序员

关于 SVM 一些疑问

  •  
  •   shuangxunian 2024 年 2 月 6 日 1640 次点击
    这是一个创建于 759 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我现在有这样的数据: x: [[1,2,3,...,15],[16,17,18,...,30],... * n ] y: [0,1,... * n] 我想对这个 15 维的数组求出来一个范围致使在里面取值得到的结果为 1 ,我搜了很久,想用 SVM 去实现,这是我的代码:

    import numpy as np from matplotlib import colors from sklearn import svm from sklearn import model_selection import matplotlib.pyplot as plt import matplotlib as mpl # 加载 data = np.loadtxt('./data.csv',dtype=float,delimiter=',') # 切分 x, y = np.split(data, (15, ), axis=1) x_train, x_test, y_train, y_test=model_selection.train_test_split(x, y, random_state=1, test_size=0.2) # 构建 def classifier(): clf = svm.SVC(C=0.8,kernel='linear',decision_function_shape='ovr') return clf # 训练 def train(clf, x_train, y_train): clf.fit(x_train, y_train.ravel()) # 定义 clf = classifier() # 调用 train(clf, x_train, y_train) # 判断 a,b 是否相等 计算 acc 的均值 def show_accuracy(a, b, tip): acc = a.ravel() == b.ravel() print('%s Accuracy:%.3f' %(tip, np.mean(acc))) # 分别打印训练集和测试集的准确率 score(x_train, y_train)表示输出 x_train,y_train 在模型上的准确率 def print_accuracy(clf, x_train, y_train, x_test, y_test): print('training prediction:%.3f' %(clf.score(x_train, y_train))) print('test data prediction:%.3f' %(clf.score(x_test, y_test))) # 原始结果和预测结果进行对比 predict() 表示对 x_train 样本进行预测,返回样本类别 show_accuracy(clf.predict(x_train), y_train, 'traing data') show_accuracy(clf.predict(x_test), y_test, 'testing data') print_accuracy(clf, x_train, y_train, x_test, y_test) 

    佬们可以帮我斧正一下吗,有哪里需要改一下?我一直感觉前面有一层雾蒙蒙的东西我理解不上来

    1 条回复    2024-02-08 10:16:38 +08:00
    kang773371222
        1
    kang773371222  
       2024 年 2 月 8 日
    SVM 支持分类和回归,你确定你用的是支持分类的应该就行
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1594 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 16:28 PVG 00:28 LAX 08:28 JFK 11:28
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86