分类Classification(决策树 DecisionTree 朴素贝叶斯 Naive Bayesian)

本文介绍了人工分类和逻辑分类的基本概念,重点探讨了朴素贝叶斯分类的算法原理,包括贝叶斯定理及其应用。此外,还详细讲解了如何划分训练集和测试集、进行交叉验证,并通过混淆矩阵和分类报告评估模型性能。最后,讨论了决策树分类,涉及叶子节点投票、验证曲线、学习曲线以及特征编码选择。

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

八、人工分类

输入1 输入2 输出
3 1 0
2 5 1
1 8 1
6 4 0
5 2 0
3 5 1
4 7 1
4 -1 0
6 8
5 1
import numpy as np
import matplotlib.pyplot as mp
x = np.array([
    [3, 1],
    [2, 5],
    [1, 8],
    [6, 4],
    [5, 2],
    [3, 5],
    [4, 7],
    [4, -1]])
y = np.array([0, 1, 1, 0, 0, 1, 1, 0])

# l左边界,r右边界,h水平边界
l, r, h = x[:, 0].min() - 1, x[:, 0].max() + 1, 0.005
# 
b, t, v = x[:, 1].min() - 1, x[:, 1].max() + 1, 0.005

grid_x = np.meshgrid(np.arange(l, r, h), np.arange(b, t, v))
flat_x = np.c_[grid_x[0].ravel(), grid_x[1].ravel()]
flat_y = np.zeros(len(flat_x), dtype=int)
flat_y[flat_x[:, 0] < flat_x[:, 1]] = 1
grid_y = flat_y.reshape(grid_x[0].shape)

mp.figure('Simple Classification', dpi=120)
mp.title('Simple Classification', fontsize=20)
mp.xlabel('x', fontsize=14)
mp.ylabel('y', fontsize=14)
mp.tick_params(labelsize=10)
mp.pcolormesh(grid_x[0], grid_x[1], grid_y, cmap='gray')
mp.scatter(x[:, 0], x[:, 1], c=y, cmap='brg', s=80)

mp.show()

png

九、逻辑分类

y = w 0 + w 1 x 1 + w 2 x 2 y = w_0+w_1x_1+w_2x_2 y=w0+w1x1+w2x2

  • 连续的预测值->离散的预测值,使用逻辑函数:

s i g m o i d = 1 1 + e − x sigmoid=\frac{1}{1+e^-x} sigmoid=1+ex1

import numpy as np
import matplotlib.pyplot as mp
x = np.linspace(-10, 10, 1000)
y = 1 / (1 + np.exp(-x))
mp.figure('Sigmoid', dpi=120)
mp.title('Sigmoid', fontsize=20)
mp.xlabel('x', fontsize=14)
mp.ylabel('y', fontsize=14)
mp.tick_params(labelsize=10)
mp.grid(linestyle=':')
mp.plot(x, y, c='dodgerblue')
mp.show()

png

  • 非线性化

y = 1 1 + e − ( w 0 + w 1 x 1 + w 2 x 2 ) y=\frac{1}{1+e^-(w0+w1x1+w2x2)} y=1+e(w0+w1x1+w2x2)1

  • 将预测函数的输出看做输入被划分为1类的概率,择概率大的类别作为预测结果。
输入1 输入2 概率 预测结果
3 1 0.2 0
2 5 0.8 1
1 8 0.7 1
6 4 0.3 0
import numpy as np
import sklearn.linear_model as lm
import matplotlib.pyplot as mp
x = np.array([
    [3, 1],
    [2, 5],
    [1, 8],
    [6, 4],
    [5, 2],
    [3, 5],
    [4, 7],
    [4, -1]])
y = np.array([0, 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值