SVM 代码示例

本文通过使用Python的scikit-learn库实现支持向量机(SVM)分类器,并在地形数据集上进行训练与测试。从数据准备到模型训练、预测直至评估准确率,详细展示了SVM的工作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关住 公 纵 号 “  阿蒙课程分享    ”  获得学习资料及趣味分享 


import sys

from class_vis import prettyPicture
from prep_terrain_data import makeTerrainData


import matplotlib.pyplot as plt
import copy
import numpy as np
import pylab as pl




features_train, labels_train, features_test, labels_test = makeTerrainData()




########################## SVM #################################
### we handle the import statement and SVC creation for you here
from sklearn.svm import SVC


clf = SVC(kernel="linear")




#### now your job is to fit the classifier
#### using the training features/labels, and to
#### make a set of predictions on the test data


clf.fit(features_train, labels_train)




#### store your predictions in a list named pred


pred = clf.predict(features_test)






from sklearn.metrics import accuracy_score
acc = accuracy_score(pred, labels_test)


def submitAccuracy():
    return acc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值