自定义数据集 使用scikit-learn中svm的包实现svm分类

import numpy as np
import matplotlib.pyplot as plt

points = np.array([[1.9, 1.2],
                   [1.5, 2.1],
                   [1.9, 0.5],
                   [1.5, 0.9],
                   [0.9, 1.2],
                   [1.1, 1.7],
                   [1.4, 1.1]])

points2 = np.array([[3.2, 3.2],
                    [3.7, 2.9],
                    [3.2, 2.6],
                    [1.7, 3.3],
                    [3.4, 2.6],
                    [4.1, 2.3],
                    [3.0, 2.9]])

# 合并为一个数据集
x1_data = np.concatenate((points[:, 0], points2[:, 0]))  # 所有的 x1 坐标
x2_data = np.concatenate((points[:, 1], points2[:, 1]))  # 所有的 x2 坐标

# 创建标签
y = np.concatenate((np.ones(points.shape[0]), -np.ones(points2.shape[0])))

# 初始化超平面的参数 w1, w2 和偏置 b
w1 = 0.1
w2 = 0.1
b = 0

# 学习率
learning_rate = 0.05

# 数据集的大小
l_data = x1_data.size

# 创建图形和子图
fig, (ax1, ax2) = plt.subplots(2, 1)

# 初始化存储每一步的损失值和迭代步数
step_list 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值