K-近邻和神经网络

news2024/9/9 6:28:27

K-近邻(K-NN, K-Nearest Neighbors)

原理

K-近邻(K-NN)是一种非参数分类和回归算法。K-NN 的主要思想是根据距离度量(如欧氏距离)找到训练数据集中与待预测样本最近的 K 个样本,并根据这 K 个样本的标签来进行预测。对于分类任务,K-NN 通过投票的方式选择出现最多的类别作为预测结果;对于回归任务,K-NN 通过计算 K 个最近邻样本的平均值来进行预测。

公式

K-NN 的主要步骤包括:

  1. 计算待预测样本与训练集中每个样本之间的距离。常用的距离度量包括欧氏距离、曼哈顿距离等。

  2. 找到距离最近的 K 个样本。
  3. 对于分类任务,通过投票决定预测结果:

其中,Nk 表示样本 x 的 K 个最近邻样本集合,I 是指示函数。

  1. 对于回归任务,通过计算平均值决定预测结果:

生活场景应用的案例

手写数字识别:K-NN 可以用于手写数字识别任务。假设我们有一个手写数字的图片数据集,每张图片都被标注了对应的数字。我们可以使用 K-NN 模型来识别新图片中的数字。

案例描述

假设我们有一个手写数字图片的数据集,包括以下特征:

  • 图片像素值(每张图片由一个固定大小的像素矩阵表示)

我们希望通过这些像素值来预测图片中的数字。我们可以使用 K-NN 模型进行训练和预测。训练完成后,我们可以使用模型来识别新图片中的数字,并评估模型的性能。

代码解析

下面是一个使用 Python 实现上述手写数字识别案例的示例,使用了 scikit-learn 库。

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
import matplotlib.pyplot as plt
from sklearn.datasets import load_digits

# 载入手写数字数据集
digits = load_digits()
X = digits.data
y = digits.target

# 拆分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 创建K-NN模型并训练
k = 5
model = KNeighborsClassifier(n_neighbors=k)
model.fit(X_train, y_train)

# 预测
y_pred = model.predict(X_test)

# 评估模型
accuracy = accuracy_score(y_test, y_pred)
cm = confusion_matrix(y_test, y_pred)
report = classification_report(y_test, y_pred)

print(f"Accuracy: {accuracy}")
print("Confusion Matrix:")
print(cm)
print("Classification Report:")
print(report)

# 可视化部分测试结果
fig, axes = plt.subplots(1, 5, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, y_pred):
    ax.set_axis_off()
    image = image.reshape(8, 8)
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {prediction}')
plt.show()

在这个示例中:

  1. 我们使用了 sklearn.datasets 中的手写数字数据集。这个数据集包含了 8x8 像素的图片,每张图片代表一个手写数字。
  2. 将数据集拆分为训练集和测试集。
  3. 使用训练集训练 K-NN 分类模型。
  4. 通过测试集进行预测并评估模型的性能。
  5. 输出准确率(accuracy)、混淆矩阵(confusion matrix)和分类报告(classification report)。
  6. 可视化部分测试结果,展示模型的预测效果。

这个案例展示了如何使用 K-NN 模型来识别手写数字,基于图片的像素值特征。模型训练完成后,可以用于预测新图片中的数字,并帮助解决实际的手写数字识别问题。

神经网络(Neural Network)

原理

神经网络是一种模仿生物神经元结构的计算模型,由多个节点(神经元)和连接(权重)组成。神经网络主要由输入层、隐藏层和输出层构成,每一层包含若干神经元。通过层与层之间的连接和激活函数(如ReLU、Sigmoid等),神经网络能够拟合复杂的非线性关系,实现分类、回归等任务。

训练神经网络的过程通常使用反向传播算法,通过计算损失函数的梯度来调整网络的权重,以最小化预测误差。

公式
  1. 神经元的线性组合

其中,xi 是输入,wi 是权重,b 是偏置,z 是神经元的加权和。

  1. 激活函数: 常用的激活函数包括:
  • Sigmoid 函数:

  • ReLU 函数:

  1. 反向传播

反向传播算法通过计算损失函数的梯度来更新权重:

其中,η 是学习率,L 是损失函数。

生活场景应用的案例

图像分类:神经网络广泛应用于图像分类任务。假设我们有一个包含手写数字图片的数据集,每张图片都被标注了对应的数字。我们可以使用神经网络模型来识别新图片中的数字。

案例描述

假设我们有一个手写数字图片的数据集,包括以下特征:

  • 图片像素值(每张图片由一个固定大小的像素矩阵表示)

我们希望通过这些像素值来预测图片中的数字。我们可以使用神经网络模型进行训练和预测。训练完成后,我们可以使用模型来识别新图片中的数字,并评估模型的性能。

代码解析

下面是一个使用 Python 实现上述手写数字识别案例的示例,使用了 tensorflowkeras 库。

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.utils import to_categorical
from sklearn.datasets import load_digits

# 载入手写数字数据集
digits = load_digits()
X = digits.images
y = digits.target

# 预处理数据
X = X / 16.0  # 将像素值归一化到 [0, 1]
y = to_categorical(y, num_classes=10)  # 将标签转换为one-hot编码

# 调整数据维度以适应TensorFlow模型
X = X.reshape(-1, 8, 8, 1)  # 使用-1使reshape自动计算样本数量

# 拆分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 创建神经网络模型
model = Sequential([
    Flatten(input_shape=(8, 8, 1)),  # 展平输入图像
    Dense(128, activation='relu'),  # 隐藏层,包含128个神经元
    Dense(64, activation='relu'),  # 隐藏层,包含64个神经元
    Dense(10, activation='softmax')  # 输出层,包含10个神经元,对应10个类别
])

# 编译模型
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# 训练模型
model.fit(X_train, y_train, epochs=20, batch_size=32, validation_split=0.2)

# 评估模型
loss, accuracy = model.evaluate(X_test, y_test)
y_pred = model.predict(X_test)
y_pred_classes = np.argmax(y_pred, axis=1)
y_true = np.argmax(y_test, axis=1)

print(f"Accuracy: {accuracy}")
print("Classification Report:")
print(classification_report(y_true, y_pred_classes))

# 可视化部分测试结果
fig, axes = plt.subplots(1, 5, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, y_pred_classes):
    ax.set_axis_off()
    image = image.reshape(8, 8)  # 确保图像形状正确
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {prediction}')
plt.show()

在这个示例中:

  1. 我们使用了 sklearn.datasets 中的手写数字数据集。这个数据集包含了 8x8 像素的图片,每张图片代表一个手写数字。
  2. 将数据集拆分为训练集和测试集,并对数据进行预处理,将像素值归一化并将标签转换为 one-hot 编码。
  3. 创建了一个包含两个隐藏层的神经网络模型。
  4. 使用训练集训练神经网络模型。
  5. 通过测试集进行预测并评估模型的性能。
  6. 输出准确率(accuracy)和分类报告(classification report)。
  7. 可视化部分测试结果,展示模型的预测效果。

这个案例展示了如何使用神经网络模型来识别手写数字,基于图片的像素值特征。模型训练完成后,可以用于预测新图片中的数字,并帮助解决实际的手写数字识别问题。

具体应用
  • 对预测结果进行可视化展示
    • 在预测结果后,展示原始图片及其预测结果。
  • 保存和加载训练好的模型
    • 保存训练好的模型。
    • 加载已保存的模型进行预测。
import os
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.utils import to_categorical
from sklearn.datasets import load_digits
from PIL import Image  # 用于加载自定义图片

# 载入手写数字数据集
digits = load_digits()
X = digits.images
y = digits.target

# 预处理数据
X = X / 16.0  # 将像素值归一化到 [0, 1]
y = to_categorical(y, num_classes=10)  # 将标签转换为one-hot编码

# 调整数据维度以适应TensorFlow模型
X = X.reshape(-1, 8, 8, 1)  # 使用-1使reshape自动计算样本数量

# 拆分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 创建神经网络模型
model = Sequential([
    Flatten(input_shape=(8, 8, 1)),  # 展平输入图像
    Dense(128, activation='relu'),  # 隐藏层,包含128个神经元
    Dense(64, activation='relu'),  # 隐藏层,包含64个神经元
    Dense(10, activation='softmax')  # 输出层,包含10个神经元,对应10个类别
])

# 编译模型
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# 训练模型
model.fit(X_train, y_train, epochs=20, batch_size=32, validation_split=0.2)

# 保存训练好的模型
model.save('digit_recognition_model.h5')

# 加载训练好的模型
# model = load_model('digit_recognition_model.h5')

# 评估模型
loss, accuracy = model.evaluate(X_test, y_test)
y_pred = model.predict(X_test)
y_pred_classes = np.argmax(y_pred, axis=1)
y_true = np.argmax(y_test, axis=1)

print(f"Accuracy: {accuracy}")
print("Classification Report:")
print(classification_report(y_true, y_pred_classes))

# 可视化部分测试结果
fig, axes = plt.subplots(1, 5, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, y_pred_classes):
    ax.set_axis_off()
    image = image.reshape(8, 8)  # 确保图像形状正确
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {prediction}')
plt.show()

# 加载并预处理单张图片
def load_and_preprocess_image(filepath):
    img = Image.open(filepath).convert('L')  # 转换为灰度图像
    img = img.resize((8, 8))  # 调整图像大小为8x8
    img = np.array(img) / 16.0  # 归一化像素值
    img = img.reshape(1, 8, 8, 1)  # 调整图像维度
    return img

# 加载并预处理文件夹中的所有图片
def load_images_from_folder(folder):
    images = []
    filepaths = []
    for filename in os.listdir(folder):
        if filename.endswith(('png', 'jpg', 'jpeg')):
            filepath = os.path.join(folder, filename)
            img = load_and_preprocess_image(filepath)
            images.append(img)
            filepaths.append(filepath)
    return np.vstack(images), filepaths

# 使用模型预测文件夹中的多张图片
def predict_custom_images_from_folder(folder):
    imgs, filepaths = load_images_from_folder(folder)
    preds = model.predict(imgs)
    pred_classes = np.argmax(preds, axis=1)
    return pred_classes, filepaths

# 示例:预测文件夹中的多张自定义图片并展示结果
custom_image_folder = 'path/to/your/folder'  # 替换为自定义图片文件夹路径
predicted_classes, filepaths = predict_custom_images_from_folder(custom_image_folder)

# 打印预测结果并可视化
fig, axes = plt.subplots(1, len(filepaths), figsize=(15, 3))
for ax, filepath, pred_class in zip(axes, filepaths, predicted_classes):
    ax.set_axis_off()
    img = Image.open(filepath).convert('L')
    img = img.resize((8, 8))
    img = np.array(img
    ax.imshow(img, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {pred_class}')
    print(f'The predicted class for {filepath} is: {pred_class}')
plt.show()

a. 添加更多的训练数据来提高模型的准确性。

b. 使用混淆矩阵来详细分析模型的分类结果。

import os
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix, ConfusionMatrixDisplay
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from sklearn.datasets import load_digits
from PIL import Image

# 载入手写数字数据集
digits = load_digits()
X = digits.images
y = digits.target

# 预处理数据
X = X / 16.0  # 将像素值归一化到 [0, 1]
y = to_categorical(y, num_classes=10)  # 将标签转换为one-hot编码

# 调整数据维度以适应TensorFlow模型
X = X.reshape(-1, 8, 8, 1)  # 使用-1使reshape自动计算样本数量

# 拆分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 再拆分训练集以创建验证集
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2, random_state=42)

# 数据扩充
datagen = ImageDataGenerator(
    rotation_range=10,
    zoom_range=0.1,
    width_shift_range=0.1,
    height_shift_range=0.1
)
datagen.fit(X_train)

# 创建神经网络模型
model = Sequential([
    Flatten(input_shape=(8, 8, 1)),  # 展平输入图像
    Dense(128, activation='relu'),  # 隐藏层,包含128个神经元
    Dense(64, activation='relu'),  # 隐藏层,包含64个神经元
    Dense(10, activation='softmax')  # 输出层,包含10个神经元,对应10个类别
])

# 编译模型
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# 训练模型
model.fit(datagen.flow(X_train, y_train, batch_size=32), epochs=20, validation_data=(X_val, y_val))

# 保存训练好的模型
model.save('digit_recognition_model.h5')

# 加载训练好的模型
# model = load_model('digit_recognition_model.h5')

# 评估模型
loss, accuracy = model.evaluate(X_test, y_test)
y_pred = model.predict(X_test)
y_pred_classes = np.argmax(y_pred, axis=1)
y_true = np.argmax(y_test, axis=1)

print(f"Accuracy: {accuracy}")
print("Classification Report:")
print(classification_report(y_true, y_pred_classes))

# 生成混淆矩阵
cm = confusion_matrix(y_true, y_pred_classes)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=np.arange(10))
disp.plot(cmap=plt.cm.Blues)
plt.show()

# 可视化部分测试结果
fig, axes = plt.subplots(1, 5, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, y_pred_classes):
    ax.set_axis_off()
    image = image.reshape(8, 8)  # 确保图像形状正确
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {prediction}')
plt.show()

# 加载并预处理单张图片
def load_and_preprocess_image(filepath):
    img = Image.open(filepath).convert('L')  # 转换为灰度图像
    img = img.resize((8, 8))  # 调整图像大小为8x8
    img = np.array(img) / 16.0  # 归一化像素值
    img = img.reshape(1, 8, 8, 1)  # 调整图像维度
    return img

# 加载并预处理文件夹中的所有图片
def load_images_from_folder(folder):
    images = []
    filepaths = []
    for filename in os.listdir(folder):
        if filename.endswith(('png', 'jpg', 'jpeg')):
            filepath = os.path.join(folder, filename)
            img = load_and_preprocess_image(filepath)
            images.append(img)
            filepaths.append(filepath)
    return np.vstack(images), filepaths

# 使用模型预测文件夹中的多张图片
def predict_custom_images_from_folder(folder):
    imgs, filepaths = load_images_from_folder(folder)
    preds = model.predict(imgs)
    pred_classes = np.argmax(preds, axis=1)
    return pred_classes, filepaths

# 示例:预测文件夹中的多张自定义图片并展示结果
custom_image_folder = 'path/to/your/folder'  # 替换为自定义图片文件夹路径
predicted_classes, filepaths = predict_custom_images_from_folder(custom_image_folder)

# 打印预测结果并可视化
fig, axes = plt.subplots(1, len(filepaths), figsize=(15, 3))
for ax, filepath, pred_class in zip(axes, filepaths, predicted_classes):
    ax.set_axis_off()
    img = Image.open(filepath).convert('L')
    img = img.resize((8, 8))
    img = np.array(img)
    ax.imshow(img, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {pred_class}')
    print(f'The predicted class for {filepath} is: {pred_class}')
plt.show()

a. 使用更多的手写数字样本进行训练,以提高模型对手写数字的识别能力。

b. 尝试使用不同的模型架构,如卷积神经网络(CNN),以提高模型的识别准确率。

import os
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix, ConfusionMatrixDisplay
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from sklearn.datasets import load_digits
from PIL import Image

# 载入手写数字数据集
digits = load_digits()
X = digits.images
y = digits.target

# 预处理数据
X = X / 16.0  # 将像素值归一化到 [0, 1]
y = to_categorical(y, num_classes=10)  # 将标签转换为one-hot编码

# 调整数据维度以适应TensorFlow模型
X = X.reshape(-1, 8, 8, 1)  # 使用-1使reshape自动计算样本数量

# 拆分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 再拆分训练集以创建验证集
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2, random_state=42)

# 数据扩充
datagen = ImageDataGenerator(
    rotation_range=5,
    zoom_range=0.05,
    width_shift_range=0.05,
    height_shift_range=0.05
)
datagen.fit(X_train)

# 创建神经网络模型
model = Sequential([
    Flatten(input_shape=(8, 8, 1)),  # 展平输入图像
    Dense(128, activation='relu'),  # 隐藏层,包含128个神经元
    Dense(64, activation='relu'),  # 隐藏层,包含64个神经元
    Dense(10, activation='softmax')  # 输出层,包含10个神经元,对应10个类别
])

# 编译模型
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# 训练模型
history = model.fit(datagen.flow(X_train, y_train, batch_size=32), epochs=20, validation_data=(X_val, y_val))

# 保存训练好的模型
model.save('digit_recognition_model.h5')

# 加载训练好的模型
# model = load_model('digit_recognition_model.h5')

# 评估模型
loss, accuracy = model.evaluate(X_test, y_test)
y_pred = model.predict(X_test)
y_pred_classes = np.argmax(y_pred, axis=1)
y_true = np.argmax(y_test, axis=1)

print(f"Accuracy: {accuracy}")
print("Classification Report:")
print(classification_report(y_true, y_pred_classes))

# 生成混淆矩阵
cm = confusion_matrix(y_true, y_pred_classes)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=np.arange(10))
disp.plot(cmap=plt.cm.Blues)
plt.show()

# 可视化部分测试结果
fig, axes = plt.subplots(1, 5, figsize=(10, 3))
for ax, image, prediction in zip(axes, X_test, y_pred_classes):
    ax.set_axis_off()
    image = image.reshape(8, 8)  # 确保图像形状正确
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {prediction}')
plt.show()

# 加载并预处理单张图片
def load_and_preprocess_image(filepath):
    img = Image.open(filepath).convert('L')  # 转换为灰度图像
    img = img.resize((8, 8))  # 调整图像大小为8x8
    img = np.array(img) / 255.0  # 归一化像素值到 [0, 1]
    img = img.reshape(1, 8, 8, 1)  # 调整图像维度
    return img

# 加载并预处理文件夹中的所有图片
def load_images_from_folder(folder):
    images = []
    filepaths = []
    for filename in os.listdir(folder):
        if filename.endswith(('png', 'jpg', 'jpeg')):
            filepath = os.path.join(folder, filename)
            img = load_and_preprocess_image(filepath)
            images.append(img)
            filepaths.append(filepath)
    return np.vstack(images), filepaths

# 使用模型预测文件夹中的多张图片
def predict_custom_images_from_folder(folder):
    imgs, filepaths = load_images_from_folder(folder)
    preds = model.predict(imgs)
    pred_classes = np.argmax(preds, axis=1)
    return pred_classes, filepaths

# 示例:预测文件夹中的多张自定义图片并展示结果
custom_image_folder = 'path/to/your/folder'  # 替换为自定义图片文件夹路径
predicted_classes, filepaths = predict_custom_images_from_folder(custom_image_folder)

# 打印预测结果并可视化
fig, axes = plt.subplots(1, len(filepaths), figsize=(15, 3))
for ax, filepath, pred_class in zip(axes, filepaths, predicted_classes):
    ax.set_axis_off()
    img = Image.open(filepath).convert('L')
    img = img.resize((8, 8))
    img = np.array(img)
    ax.imshow(img, cmap=plt.cm.gray_r, interpolation='nearest')
    ax.set_title(f'Pred: {pred_class}')
    print(f'The predicted class for {filepath} is: {pred_class}')
plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1962509.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

安科瑞ASJ系列智能剩余电流继电器介绍

产品概述: 安科瑞ASJ系列智能剩余电流继电器是一种重要的电气安全保护设备,‌主要用于交流50Hz、‌额定电压400V及以下的TT和TN系统配电线路中。‌该系列继电器的主要功能包括对电气线路进行接地故障保护,‌以防止接地故障电流引起的设备损坏…

C语言家教记录(一)

C语言家教记录(一) 导语C语言简介特点优点缺点 Codeblocks安装和使用简单程序结构变量(常量)和赋值类型声明常量赋值标识符 基本运算输入输出printf基本格式转义序列 scanf转换说明 示例程序总结和复习 导语 本次授课内容如下&am…

一句JS代码,实现随机颜色的生成

今天我们只用 一句JS代码,实现随机颜色的生成,首先看一下效果: 每次刷新浏览器背景颜色都不一样 实现此效果的JS函数 : let randomColor () > ...: 定义一个箭头函数randomColor,用于生成一个随机颜色。 Math.ra…

苹果发布iPhone AI,Apple Intelligence初版落地!未融入ChatGPT,仅面向付费开发者

本文首发于公众号“AntDream”,欢迎微信搜索“AntDream”或扫描文章底部二维码关注,和我一起每天进步一点点 苹果公司Apple Intelligence初版落地:iPhone AI引领智能化新篇章 在全球科技领域,苹果公司一直以其创新精神和前沿技术…

java算法day27

java算法day27 动态规划初步总结509 斐波那契数杨辉三角打家劫舍完全平方数 动态规划初步总结 如果你感觉某个问题有很多重叠子问题,使用动态规划是最有效的。 动态规划的过程就是每一个状态一定是由上一个状态推导出来的,这一点就区分于贪心了。贪心是…

热力图大揭秘!Matplotlib教你如何画出让数据‘火辣辣‘的激情图!

1. 引言 嘿,小伙伴们!今天咱们来点不一样的,走进Matplotlib的神奇世界,一起绘制那让人热血沸腾的热力图!别误会,这可不是什么天气预报图,而是让数据“火辣辣”展现自我的秘密武器。想象一下&am…

PHP进阶-CentOS7部署LNMP服务架构的项目

在开发和部署Web应用时,LNMP(Linux、Nginx、MySQL、PHP)的组合是非常常见的。这篇博客将介绍如何通过一个简单的脚本,在CentOS 7上部署LNMP,并将PHP项目自动部署到服务器上。这不仅可以节省大量的时间,还能…

《系统架构设计师教程(第2版)》第13章-层次式架构设计理论与实践-03-中间层(业务层|逻辑层)架构设计

文章目录 1. 业务逻辑层组件设计1.1 业务逻辑组件的实现类1.2 业务逻辑组件的配置 2. 业务逻辑层工作流设计2.1 工作流2.2 工作流参考模型2.2.1 概述2.2.1 工作流参考模型 3. 业务逻辑层实体设计3.1 业务逻辑层实体概述3.2 逻辑层实体的表示方法3.2.1 XML表示业务层实体3.2.2 通…

Prometheus+Grafana 监控平台实践-搭建常用服务监控告警

前言 Prometheus 是一个开放性的监控解决方案,通过各种 Exporter 采集当前主机/服务的数据,和 Grafana 相结合可以实现强大的监控和可视化功能 本篇将分享使用 docker compose 构建 Prometheus+Grafana,并监控之前文章所搭建的主机&服务,分享日常使用的一些使用经验 文…

Qt基础 | UDP通信 | UDP单播、广播、组播的介绍与实现

文章目录 一、QUdpSocket 实现 UDP 通信1.UDP 通信概述2.UDP 单播和广播2.1 主窗口类定义和构造函数2.2 UDP通信实现 3.UDP 组播3.1 主窗口类定义和构造函数3.2 组播功能的程序实现 Qt 网络模块: Qt基础 | 主机信息查询 | QHostInfo的介绍和使用 | QNetworkInterfac…

排序算法:选择排序,golang实现

目录 前言 选择排序 代码示例 1. 算法包 2. 选择排序代码 3. 模拟排序 4. 运行程序 5. 从大到小排序 循环细节 外层循环 内层循环 总结 循环次数测试 假如 10 条数据进行排序 假如 20 条数据进行排序 假如 30 条数据进行排序 选择排序的适用场景 1. 数据规模…

SAP PowerDesigner@官网下载

背景 略 问题 略 解决 用户可以通过访问SAP支持网站的首页(‌https://support.sap.com/home.html)‌,‌然后导航到“Software Downloads”(‌软件下载)‌部分来访问SAP软件的下载入口。‌在这里,‌用户可…

HCIP笔记1

hcia复习 osi--开放式系统互联参考模型---7层参考模型 tcp/ip协议栈道---4或5层 osi: 应用层 抽象语言-->编码 表示层 编码-->二进制 会话层 提供应用程序的会话地址 上三层为应用程序对数据流量进行加工及处理的阶段 传输层 分段、端口号 tcp/udp 网…

Apache2 Ubuntu-XXE漏洞渗透

Apache2 Ubuntu-XXE漏洞渗透 Apache2 Ubuntu Default Page 是一个包含xxe漏洞的页面,如何找到和利用xxe漏洞,并找到flag呢? 第一步:先打开其网页 当安装好虚拟机环境后,打开虚拟机我们并不知道它linux的账号密码 因…

通配符https证书的申请途径和配置方法

一、通配符SSL证书的功能 通配符SSL证书,也被称为泛域名证书,是一种特殊类型的SSL证书,它能够保护一个主域名及其所有次级子域名(不可跨级保护)。例如,如果您的主域名是example.com,那么一个通…

Vue2从基础到实战(v-bind对于样式控制的增强-操作style,v-model在其他表单元素的使用)

v-bind对于样式控制的增强-操作style 语法&#xff1a;style"样式对象" <div class"box" :style"{ CSS属性名1: CSS属性值, CSS属性名2: CSS属性值 }"></div> 代码解析&#xff1a; HTML结构&#xff1a; 包含了一个div元素&…

什么是数据血缘?怎么做好数据血缘分析?

目录 一、什么是数据血缘&#xff1f; 二、数据血缘关系的四大特征 三、数据血缘分析怎么做&#xff1f; 1.定义元数据模型 2.收集元数据 3.建立血缘关系模型 4.追踪数据流动 5.可视化分析 6.集成到数据治理中 7.持续更新和维护 8.应用分析结果 四、数据血缘技术趋势 1.通用的血…

51单片机-第六节-LED点阵屏与_74HC595_

1.LED点阵屏的结构&#xff1a; 与数码管相同&#xff08;数码管只是把LED排成8字结构&#xff09;&#xff0c;8*8的点阵屏有8816个引脚。 双色点阵屏有82*824个引脚&#xff0c;结构如图&#xff1a; 注&#xff1a;点阵屏引脚多为乱序排列&#xff0c; 控制需看单片机说…

基于SpringBoot+Vue的大学生租房系统(带1w+文档)

基于SpringBootVue的大学生租房系统(带1w文档) 基于SpringBootVue的大学生租房系统(带1w文档) 该系统主要实现了用户和房主通过系统注册用户&#xff0c;登录系统后能够编辑自己的个人信息、查看首页&#xff0c;房屋信息&#xff0c;房屋评价&#xff0c;公告资讯&#xff0c;…

Linux第七节课gcc与g++

一、补充权限 普通用户无法执行sudo&#xff1a; 通过sudo执行后显示不在sudoers file中&#xff01;&#xff08;张三不被信任&#xff01;&#xff09; 需要修改配置文件&#xff08;白名单&#xff01;&#xff09; 配置文件位于以下目录&#xff1a; ls /etc/sudoers -…