当前位置: 首页 > news >正文

K-近邻和神经网络

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))  # 调整图像大小为8x8img = 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(imgax.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))  # 调整图像大小为8x8img = 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))  # 调整图像大小为8x8img = 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()

相关文章:

K-近邻和神经网络

K-近邻(K-NN, K-Nearest Neighbors) 原理 K-近邻(K-NN)是一种非参数分类和回归算法。K-NN 的主要思想是根据距离度量(如欧氏距离)找到训练数据集中与待预测样本最近的 K 个样本,并根据这 K 个…...

用EasyV全景图低成本重现真实场景,360°感受数字孪生

全景图,即借助绘画、相片、视频、三维模型等形式,通过广角的表现手段,尽可能多表现出周围的环境。避免了一般平面效果图视角单一,不能带来全方位视角的缺陷,能够全方位的展示360度球型范围内的所有景致,最大…...

【Golang 面试 - 进阶题】每日 3 题(九)

✍个人博客:Pandaconda-CSDN博客 📣专栏地址:http://t.csdnimg.cn/UWz06 📚专栏简介:在这个专栏中,我将会分享 Golang 面试中常见的面试题给大家~ ❤️如果有收获的话,欢迎点赞👍收藏…...

孟德尔随机化、R语言,报错,如何解决?

🏆本文收录于《CSDN问答解惑-专业版》专栏,主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收…...

一文剖析高可用向量数据库的本质

面对因电力故障、网络问题或人为操作失误等导致的服务中断,数据库系统高可用能够保证系统在这些情况下仍然不间断地提供服务。如果数据库系统不具备高可用性,那么系统就需要承担停机和数据丢失等重大风险,而这些风险极有可能造成用户流失&…...

JavaScript青少年简明教程:异常处理

JavaScript青少年简明教程:异常处理 在 JavaScript 中,异常指的是程序执行过程中出现的错误或异常情况。这些错误可能导致程序无法正常执行,甚至崩溃。ECMA-262规范了多种JavaScript错误类型,这些类型都继承自Error基类。主要的错…...

科普文:Lombok使用及工作原理详解

1. 概叙 Lombok是什么? Project Lombok 是一个 JAVA 库,它可以自动插入编辑器和构建工具,为您的 JAVA 锦上添花。再也不要写另一个 getter/setter 或 equals 等方法,只要有一个注注解,你的类就有一个功能齐全的生成器…...

飞致云开源社区月度动态报告(2024年7月)

自2023年6月起,中国领先的开源软件公司FIT2CLOUD飞致云以月度为单位发布《飞致云开源社区月度动态报告》,旨在向广大社区用户同步飞致云旗下系列开源软件的发展情况,以及当月主要的产品新版本发布、社区运营成果等相关信息。 飞致云开源大屏…...

mybatis-plus——实现动态字段排序,根据实体获取字段映射数据库的具体字段

前言 前端需要根据表头的点击控件可以排序,虽然前端能根据当前页的数据进行对应字段的排序,但也仅局限于实现当前页的排序,无法满足全部数据的排序,所以需要走接口的查询进行排序,获取最全的排序数据 实现方案 前端…...

redis:Linux安装redis,redis常用的数据类型及相关命令

1. 什么是NoSQL nosql[not only sql]不仅仅是sql。所有非关系型数据库的统称。除去关系型数据库之外的都是非关系数据库。 1.1为什么使用NoSQL ​ NoSQL数据库相较于传统关系型数据库具有灵活性、可扩展性和高性能等优势,适合处理非结构化和半结构化数据&#xff0c…...

JavaScript 和 HTML5 Canvas实现图像绘制与处理

前言 JavaScript 和 HTML5 的 canvas 元素提供了强大的图形和图像处理功能,使得开发者能够在网页上创建动态和交互式的视觉体验。这里我们将探讨如何使用 canvas 和 JavaScript 来处理图像加载,并在其上进行图像绘制。我们将实现一个简单的示例&#xf…...

Java之Java基础二十(集合[上])

Java 集合框架可以分为两条大的支线: ①、Collection,主要由 List、Set、Queue 组成: List 代表有序、可重复的集合,典型代表就是封装了动态数组的 ArrayList 和封装了链表的 LinkedList;Set 代表无序、不可重复的集…...

【C++BFS】1162. 地图分析

本文涉及知识点 CBFS算法 LeetCode1162. 地图分析 你现在手里有一份大小为 n x n 的 网格 grid,上面的每个 单元格 都用 0 和 1 标记好了。其中 0 代表海洋,1 代表陆地。 请你找出一个海洋单元格,这个海洋单元格到离它最近的陆地单元格的距…...

实战:安装ElasticSearch 和常用操作命令

概叙 科普文:深入理解ElasticSearch体系结构-CSDN博客 Elasticsearch各版本比较 ElasticSearch 单点安装 1 创建普通用户 #1 创建普通用户名,密码 [roothlink1 lyz]# useradd lyz [roothlink1 lyz]# passwd lyz#2 然后 关闭xshell 重新登录 ip 地址…...

React-Native 宝藏库大揭秘:精选开源项目与实战代码解析

1. 引言 1.1 React-Native 简介 React-Native 是由 Facebook 开发的一个开源框架,它允许开发者使用 JavaScript 和 React 的编程模型来构建跨平台的移动应用。React-Native 的核心理念是“Learn Once, Write Anywhere”,即学习一次 React 的编程模型&am…...

数据结构:二叉树(链式结构)

文章目录 1. 二叉树的链式结构2. 二叉树的创建和实现相关功能2.1 创建二叉树2.2 二叉树的前,中,后序遍历2.2.1 前序遍历2.2.2 中序遍历2.2.3 后序遍历 2.3 二叉树节点个数2.4 二叉树叶子结点个数2.5 二叉树第k层结点个数2.6 二叉树的深度/高度2.7 二叉树…...

召唤生命,阻止轻生——《生命门外》

本书的目的,就是阻止自杀!拉回那些深陷在这样的思维当中正在挣扎犹豫的人,提醒他们珍爱生命,让更多的人,尤其是年轻人从执迷不悟的犹豫徘徊中幡然醒悟,回归正常的生活。 网络上抱孩子跳桥轻生的母亲&#…...

JVM:栈上的数据存储

文章目录 一、Java虚拟机中的基本数据类型 一、Java虚拟机中的基本数据类型 在Java中有8大基本数据类型: 这里的内存占用,指的是堆上或者数组中内存分配的空间大小,栈上的实现更加复杂。 Java中的8大数据类型在虚拟机中的实现:…...

C#实战 - C#实现发送邮件的三种方法

作者:逍遥Sean 简介:一个主修Java的Web网站\游戏服务器后端开发者 主页:https://blog.csdn.net/Ureliable 觉得博主文章不错的话,可以三连支持一下~ 如有疑问和建议,请私信或评论留言! 前言 当使用 C# 编程…...

数模原理精解【5】

文章目录 二元分布满足要求边际分布条件概率例子1例子2 损失函数概率分布期望值例 参考文献 二元分布 满足要求 连续情况下, φ ( x , y ) \varphi (x,y) φ(x,y)为随机变量 X 、 Y X、Y X、Y的联合概率分布(二元分布),如果以下条件满足: …...

大话软工笔记—需求分析概述

需求分析,就是要对需求调研收集到的资料信息逐个地进行拆分、研究,从大量的不确定“需求”中确定出哪些需求最终要转换为确定的“功能需求”。 需求分析的作用非常重要,后续设计的依据主要来自于需求分析的成果,包括: 项目的目的…...

centos 7 部署awstats 网站访问检测

一、基础环境准备(两种安装方式都要做) bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats&#xff0…...

第 86 场周赛:矩阵中的幻方、钥匙和房间、将数组拆分成斐波那契序列、猜猜这个单词

Q1、[中等] 矩阵中的幻方 1、题目描述 3 x 3 的幻方是一个填充有 从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等。 给定一个由整数组成的row x col 的 grid,其中有多少个 3 3 的 “幻方” 子矩阵&am…...

selenium学习实战【Python爬虫】

selenium学习实战【Python爬虫】 文章目录 selenium学习实战【Python爬虫】一、声明二、学习目标三、安装依赖3.1 安装selenium库3.2 安装浏览器驱动3.2.1 查看Edge版本3.2.2 驱动安装 四、代码讲解4.1 配置浏览器4.2 加载更多4.3 寻找内容4.4 完整代码 五、报告文件爬取5.1 提…...

html-<abbr> 缩写或首字母缩略词

定义与作用 <abbr> 标签用于表示缩写或首字母缩略词&#xff0c;它可以帮助用户更好地理解缩写的含义&#xff0c;尤其是对于那些不熟悉该缩写的用户。 title 属性的内容提供了缩写的详细说明。当用户将鼠标悬停在缩写上时&#xff0c;会显示一个提示框。 示例&#x…...

iOS性能调优实战:借助克魔(KeyMob)与常用工具深度洞察App瓶颈

在日常iOS开发过程中&#xff0c;性能问题往往是最令人头疼的一类Bug。尤其是在App上线前的压测阶段或是处理用户反馈的高发期&#xff0c;开发者往往需要面对卡顿、崩溃、能耗异常、日志混乱等一系列问题。这些问题表面上看似偶发&#xff0c;但背后往往隐藏着系统资源调度不当…...

虚拟电厂发展三大趋势:市场化、技术主导、车网互联

市场化&#xff1a;从政策驱动到多元盈利 政策全面赋能 2025年4月&#xff0c;国家发改委、能源局发布《关于加快推进虚拟电厂发展的指导意见》&#xff0c;首次明确虚拟电厂为“独立市场主体”&#xff0c;提出硬性目标&#xff1a;2027年全国调节能力≥2000万千瓦&#xff0…...

RabbitMQ入门4.1.0版本(基于java、SpringBoot操作)

RabbitMQ 一、RabbitMQ概述 RabbitMQ RabbitMQ最初由LShift和CohesiveFT于2007年开发&#xff0c;后来由Pivotal Software Inc.&#xff08;现为VMware子公司&#xff09;接管。RabbitMQ 是一个开源的消息代理和队列服务器&#xff0c;用 Erlang 语言编写。广泛应用于各种分布…...

《Offer来了:Java面试核心知识点精讲》大纲

文章目录 一、《Offer来了:Java面试核心知识点精讲》的典型大纲框架Java基础并发编程JVM原理数据库与缓存分布式架构系统设计二、《Offer来了:Java面试核心知识点精讲(原理篇)》技术文章大纲核心主题:Java基础原理与面试高频考点Java虚拟机(JVM)原理Java并发编程原理Jav…...

深入解析光敏传感技术:嵌入式仿真平台如何重塑电子工程教学

一、光敏传感技术的物理本质与系统级实现挑战 光敏电阻作为经典的光电传感器件&#xff0c;其工作原理根植于半导体材料的光电导效应。当入射光子能量超过材料带隙宽度时&#xff0c;价带电子受激发跃迁至导带&#xff0c;形成电子-空穴对&#xff0c;导致材料电导率显著提升。…...