《Python深度学习-Keras》精华笔记3:解决深度学习多分类问题

news2024/10/7 14:30:22

公众号:机器学习杂货店
作者:Peter
编辑:Peter

持续更新《Python深度学习》一书的精华内容,仅作为学习笔记分享。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

本文是第三篇:介绍如何使用Keras解决Python深度学习中的多分类问题

多分类问题和二分类问题的区别注意两点:

  • 最后一层的激活函数使用softmax函数输出预测类别的概率,最大概率所在的位置就是预测的类别
  • 损失函数使用分类交叉熵-categorical_crossentropy(针对0-1标签),整数标签使用(sparse_categorical_crossentropy)

运行环境:Python3.9.13 + Keras2.12.0 + tensorflow2.12.0

导入数据

机器学习中的路透社数据集是一个非常常用的数据集,它包含来自新闻专线的文本数据,主要用于文本分类任务。这个数据集是由路透社新闻机构提供的,包含了大量的新闻文章,共计22类分类标签。

  1. 该数据集的每一条新闻文章都被标记了一个或多个分类标签,这些标签表明了新闻文章的主题或类别。例如,政治、经济、体育、科技等。数据集中的每条新闻都包含文本内容和对应的分类标签,这使得路透社数据集成为机器学习领域中一个非常有价值的数据集。
  2. 路透社数据集的挑战在于数据的复杂性、多样性和快速变化。新闻文章具有各种不同的语言和格式,包括标题、段落、列表和图片等。此外,新闻文章的表述方式也各不相同,包括情感、风格和话题等。因此,路透社数据集的难度较高,需要机器学习算法具备高水平的分类能力。
  3. 路透社数据集在机器学习领域中得到了广泛应用,主要用于评估和提升文本分类算法的性能。许多机器学习算法,包括支持向量机、决策树、随机森林和神经网络等,都曾在路透社数据集上进行过测试和比较。因此,该数据集被广泛用于评估文本分类算法的性能,并已成为机器学习领域中的经典数据集之一。

In [1]:

import numpy as np
np.random.seed(1234)

import warnings 
warnings.filterwarnings("ignore")

训练集和标签

In [2]:

from keras.datasets import reuters

In [3]:

# 取出数据中前10000个词语

(train_data, train_labels), (test_data, test_labels) = reuters.load_data(num_words=10000)

数据查看

In [4]:

train_data[:2]

Out[4]:

array([list([1, 2, 2, 8, 43, 10, 447, 5, 25, 207, 270, 5, 3095, 111, 16, 369, 186, 90, 67, 7, 89, 5, 19, 102, 6, 19, 124, 15, 90, 67, 84, 22, 482, 26, 7, 48, 4, 49, 8, 864, 39, 209, 154, 6, 151, 6, 83, 11, 15, 22, 155, 11, 15, 7, 48, 9, 4579, 1005, 504, 6, 258, 6, 272, 11, 15, 22, 134, 44, 11, 15, 16, 8, 197, 1245, 90, 67, 52, 29, 209, 30, 32, 132, 6, 109, 15, 17, 12]),
       list([1, 3267, 699, 3434, 2295, 56, 2, 7511, 9, 56, 3906, 1073, 81, 5, 1198, 57, 366, 737, 132, 20, 4093, 7, 2, 49, 2295, 2, 1037, 3267, 699, 3434, 8, 7, 10, 241, 16, 855, 129, 231, 783, 5, 4, 587, 2295, 2, 2, 775, 7, 48, 34, 191, 44, 35, 1795, 505, 17, 12])],
      dtype=object)

In [5]:

len(train_data), len(test_data)

Out[5]:

(8982, 2246)

查看label中数据信息:总共是46个类别

In [6]:

train_labels[:20]  

Out[6]:

array([ 3,  4,  3,  4,  4,  4,  4,  3,  3, 16,  3,  3,  4,  4, 19,  8, 16,
        3,  3, 21], dtype=int64)

In [7]:

test_labels[:20]

Out[7]:

array([ 3, 10,  1,  4,  4,  3,  3,  3,  3,  3,  5,  4,  1,  3,  1, 11, 23,
        3, 19,  3], dtype=int64)

单词和索引的互换:

In [8]:

word_index = reuters.get_word_index()

reverse_word_index = dict([value, key] for (key, value) in word_index.items())  # 翻转过程
decoded_review = ' '.join([reverse_word_index.get(i-3, "?") for i in train_data[0]])
decoded_review

Out[8]:

'? ? ? said as a result of its december acquisition of space co it expects earnings per share in 1987 of 1 15 to 1 30 dlrs per share up from 70 cts in 1986 the company said pretax net should rise to nine to 10 mln dlrs from six mln dlrs in 1986 and rental operation revenues to 19 to 22 mln dlrs from 12 5 mln dlrs it said cash flow per share this year should be 2 50 to three dlrs reuter 3'

数据向量化

关于数据向量化的过程:

In [9]:

# 同样的向量化函数

import numpy as np

def vectorszie(seq, dim=10000):  
    """
    seq: 输入序列
    dim:10000,维度
    """
    results = np.zeros((len(seq), dim))  # 创建全0矩阵  length * dim
    for i, s in enumerate(seq):
        results[i,s] = 1.   # 将该位置的值从0变成1,如果没有出现则还是0
    return results

In [10]:

# 两个数据向量化

x_train = vectorszie(train_data)
x_test = vectorszie(test_data)  

标签向量化

针对标签向量化方法1:自定义独热编码函数

In [11]:

# 1、手动实现

def to_one_hot(labels, dimension=10000):
    results = np.zeros((len(labels), dimension))  # 全0矩阵 np.zeros((m, n))
    for i, label in enumerate(labels):
        results[i,labels] = 1.  # 一定是浮点数
    return results 

# 调用定义的函数
one_hot_train_labels = to_one_hot(train_labels)
one_hot_test_labels = to_one_hot(test_labels)

针对标签向量化方法2:基于keras内置函数来实现

In [12]:

# keras内置方法
from keras.utils.np_utils import to_categorical

one_hot_train_labels = to_categorical(train_labels)
one_hot_test_labels = to_categorical(test_labels)

整数标签处理(基于sparse_categorical_crossentropy)

如果我们不想将分类标签(46个取值)转成独热码形式,可以使用稀疏分类标签:sparse_categorical_crossentropy。

使用方法都是类似的:

y_train = np.array(train_labels)
y_test = np.array(test_labels)

model.compile(
    optimizer='rmsprop',  # 优化器
    loss='sparse_categorical_crossentropy',  # 稀疏分类损失
    metrics=['accuracy']   # 评价指标
    )

训练集和验证集

In [13]:

#  取出1000个样本作为验证集

x_val = x_train[:1000]
part_x_train = x_train[1000:]

y_val = one_hot_train_labels[:1000]
part_y_train = one_hot_train_labels[1000:]

构建网络

In [14]:

from keras import models
from keras import layers

model = models.Sequential()
model.add(layers.Dense(64, activation='relu', input_shape=(x_train.shape[1],)))  #  X_train.shape[1] = 10000
model.add(layers.Dense(64,activation="relu"))
model.add(layers.Dense(46, activation="softmax"))    #  46就是最终的分类数目

对比二分类问题,有3个需要注意的点:

  1. 网络的第一层输入的𝑠ℎ𝑎𝑝𝑒shape为𝑥𝑡𝑟𝑎𝑖𝑛xtrain的𝑠ℎ𝑎𝑝𝑒shape第二个值
  2. 网络的最后一个层是4646的𝐷𝑒𝑛𝑠𝑒Dense层(标签有46个类别);网络输出的是一个46维的向量。向量中每个元素代表不同的类别的输出概率。
  3. 采用的激活函数是𝑠𝑜𝑓𝑡𝑚𝑎𝑥softmax函数(二分类是𝑠𝑖𝑔𝑚𝑜𝑖𝑑sigmoid函数);在输出向量中的元素代表每个类别的概率,概率之和为1;𝑜𝑢𝑡𝑝𝑢𝑡[𝑖]output[i]表示第𝑖i类的概率。

编译网络

In [15]:

model.compile(optimizer='rmsprop',  # 优化器
              loss='categorical_crossentropy',  # 多分类交叉熵categorical_crossentropy
              metrics=['accuracy']   # 评价指标
             )

In [16]:

## 训练网络

In [17]:

history = model.fit(part_x_train,  # input
                    part_y_train,  # output
                    epochs=20,  # 训练20个轮次
                    batch_size=512,  # 每次迭代使用512个样本的小批量
                    validation_data=[x_val,y_val]   # 验证集的数据
                   )
Epoch 1/20
16/16 [==============================] - 1s 26ms/step - loss: 2.6860 - accuracy: 0.4868 - val_loss: 1.8084 - val_accuracy: 0.6240
Epoch 2/20
16/16 [==============================] - 0s 14ms/step - loss: 1.5509 - accuracy: 0.6750 - val_loss: 1.3812 - val_accuracy: 0.6850
Epoch 3/20
16/16 [==============================] - 0s 14ms/step - loss: 1.2006 - accuracy: 0.7357 - val_loss: 1.1962 - val_accuracy: 0.7300
......
Epoch 18/20
16/16 [==============================] - 0s 14ms/step - loss: 0.1567 - accuracy: 0.9559 - val_loss: 0.9402 - val_accuracy: 0.8110
Epoch 19/20
16/16 [==============================] - 0s 14ms/step - loss: 0.1439 - accuracy: 0.9559 - val_loss: 0.9561 - val_accuracy: 0.8040
Epoch 20/20
16/16 [==============================] - 0s 13ms/step - loss: 0.1401 - accuracy: 0.9546 - val_loss: 0.9467 - val_accuracy: 0.8090

模型概览

In [18]:

model.summary()
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 dense (Dense)               (None, 64)                640064    
                                                                 
 dense_1 (Dense)             (None, 64)                4160      
                                                                 
 dense_2 (Dense)             (None, 46)                2990      
                                                                 
=================================================================
Total params: 647,214
Trainable params: 647,214
Non-trainable params: 0
_________________________________________________________________

模型指标评估

In [19]:

x_test

Out[19]:

array([[0., 1., 1., ..., 0., 0., 0.],
       [0., 1., 1., ..., 0., 0., 0.],
       [0., 1., 1., ..., 0., 0., 0.],
       ...,
       [0., 1., 0., ..., 0., 0., 0.],
       [0., 1., 1., ..., 0., 0., 0.],
       [0., 1., 1., ..., 0., 0., 0.]])

In [20]:

one_hot_test_labels

Out[20]:

array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 1., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)

In [21]:

# one_hot_test_labels 经历了独热编码后的labels

model.evaluate(x_test, one_hot_test_labels)
71/71 [==============================] - 0s 1ms/step - loss: 1.0572 - accuracy: 0.7872

Out[21]:

[1.0572034120559692, 0.7871772050857544]

模型指标可视化

In [22]:

his_dict = history.history  # 字典类型
his_dict.keys()

Out[22]:

dict_keys(['loss', 'accuracy', 'val_loss', 'val_accuracy'])

In [23]:

import matplotlib.pyplot as plt

loss = his_dict["loss"]
val_loss = his_dict["val_loss"]
acc = his_dict["accuracy"]
val_acc = his_dict["val_accuracy"]

In [24]:

epochs = range(1, len(loss) + 1)  # 作为横轴

# 1、损失loss

plt.plot(epochs, loss, "bo", label="Training Loss")
plt.plot(epochs, val_loss, "b", label="Validation Loss")
plt.xlabel("Epochs")
plt.ylabel("Loss")
plt.legend()
plt.title("Training and Validation Loss")
plt.show()

针对精度的可视化过程:

In [25]:

# 2、精度acc

plt.clf()  #  清空图像
plt.plot(epochs, acc, "bo", label="Training Acc")
plt.plot(epochs, val_acc, "b", label="Validation Acc")
plt.xlabel("Epochs")
plt.ylabel("Acc")
plt.legend()

plt.title("Training and Validation Acc")
plt.show()

重新训练

可以看到loss在训练集上逐渐减小的;但是在验证集上到达第8轮后保持不变;精度acc也在训练集上表现良好,但是在验证集上在第9轮后基本不变。

显然是出现了过拟合。我们重新训练指定9轮

指定轮次训练

In [26]:

from keras.datasets import reuters
import numpy as np

# 取出数据中前10000个词语
(train_data, train_labels), (test_data, test_labels) = reuters.load_data(num_words=10000)

def vectorszie(seq, dim=10000):  
    """
    seq: 输入序列
    dim:10000,维度
    """
    results = np.zeros((len(seq), dim))  # 创建全0矩阵  length * dim
    for i, s in enumerate(seq):
        results[i,s] = 1.   # 将该位置的值从0变成1,如果没有出现则还是0
    return results

# 两个数据向量化
x_train = vectorszie(train_data)
x_test = vectorszie(test_data)  

# one-hot编码
from keras.utils.np_utils import to_categorical
one_hot_train_labels = to_categorical(train_labels)
one_hot_test_labels = to_categorical(test_labels)

#  取出1000个样本作为验证集
x_val = x_train[:1000]
part_x_train = x_train[1000:]
y_val = one_hot_train_labels[:1000]
part_y_train = one_hot_train_labels[1000:]

# 构建网络
from keras import models
from keras import layers

model = models.Sequential()
model.add(layers.Dense(64, activation='relu', input_shape=(x_train.shape[1],)))  #  X_train.shape[1] = 10000
model.add(layers.Dense(64,activation="relu"))
model.add(layers.Dense(46, activation="softmax"))    #  46就是最终的分类数目

# 模型编译
model.compile(optimizer='rmsprop',  # 优化器
              loss='categorical_crossentropy',  # 多分类交叉熵categorical_crossentropy
              metrics=['accuracy']   # 评价指标
             )

model.fit(part_x_train,  # input
            part_y_train,  # output
            epochs=9,  # 训练个9轮次
            verbose=0,  # 是否显示训练细节
            batch_size=512,  # 每次迭代使用512个样本的小批量
            validation_data=[x_val,y_val]   # 验证集的数据
            )

# 模型评估
model.evaluate(x_test, one_hot_test_labels)
71/71 [==============================] - 0s 1ms/step - loss: 0.9535 - accuracy: 0.7801

Out[26]:

[0.9534968733787537, 0.780053436756134]

可以看到精度接近79%

确定预测类别

如何查看预测类别?以第一个数据的预测结果为例:

In [27]:

results = model.predict(x_test)
results
71/71 [==============================] - 0s 997us/step

Out[27]:

array([[5.1504822e-04, 1.0902017e-04, 2.1993063e-04, ..., 1.9025596e-05,
        4.6712950e-07, 3.7851787e-05],
       [5.1406571e-03, 4.2032253e-02, 1.9307269e-03, ..., 1.3830569e-02,
        5.6258432e-04, 3.1604938e-04],
       [4.0979325e-03, 7.7002281e-01, 6.7354720e-03, ..., 1.8014901e-03,
        4.9561085e-03, 9.9538732e-04],
       ...,
       [6.1581237e-04, 1.1025119e-03, 3.9810984e-04, ..., 2.9050951e-05,
        2.4186371e-05, 6.5296721e-05],
       [3.6575866e-03, 1.0463378e-02, 3.1981221e-03, ..., 2.7204564e-04,
        9.7423712e-05, 1.8902053e-03],
       [1.8005458e-03, 7.0240724e-01, 1.8455695e-02, ..., 1.9976693e-04,
        5.6885678e-04, 1.8073655e-04]], dtype=float32)

In [28]:

predict_one = results[0]
predict_one

Out[28]:

array([5.1504822e-04, 1.0902017e-04, 2.1993063e-04, 3.9642093e-01,
       5.7400799e-01, 1.5043363e-04, 4.0421914e-05, 7.1661170e-06,
       3.2984249e-03, 1.5247319e-04, 3.9692928e-05, 3.0673095e-03,
       1.3204347e-03, 3.9371965e-04, 2.1458001e-04, 1.5276371e-04,
       1.8565950e-03, 1.2035699e-04, 6.1764423e-04, 7.4270181e-03,
       3.6794273e-03, 2.7725848e-03, 2.1595537e-05, 7.5044850e-04,
       1.5939959e-05, 3.3097478e-04, 9.2904102e-06, 1.1782978e-04,
       3.3141983e-05, 2.0210361e-04, 4.8371754e-04, 2.3283543e-04,
       5.7479672e-05, 3.8166454e-05, 9.9279227e-05, 3.2270618e-05,
       2.8716330e-04, 3.2858396e-05, 1.2131617e-05, 3.3482770e-04,
       9.0265028e-05, 1.7225980e-04, 4.2123888e-06, 1.9025596e-05,
       4.6712950e-07, 3.7851787e-05], dtype=float32)

In [29]:

len(predict_one)  # 总长度是46

Out[29]:

46

In [30]:

np.sum(predict_one)  # 预测总和是1

Out[30]:

1.0000002

如何找到哪个概率最大的元素所在的位置索引?使用np.argmax函数。该位置索引就是预测的最终类别。

In [31]:

np.argmax(predict_one)

Out[31]:

4

所以第一个数据预测的类别是第3类。

所有测试集的预测结果:

In [32]:

# 基于列表推导式

# 预测值
y_predict = [np.argmax(result) for result in results]  
y_predict[:20]

Out[32]:

[4, 10, 1, 4, 13, 3, 3, 3, 3, 3, 1, 4, 1, 3, 1, 11, 4, 3, 19, 3]

In [33]:

test_labels[:20]  # 真实值 

Out[33]:

array([ 3, 10,  1,  4,  4,  3,  3,  3,  3,  3,  5,  4,  1,  3,  1, 11, 23,
        3, 19,  3], dtype=int64)

In [34]:

from sklearn.metrics import classification_report, confusion_matrix, r2_score, recall_score, accuracy_score

In [35]:

# 精度、R2

print("多分类预测建模的精度acc为: ",accuracy_score(test_labels,y_predict))
print("多分类预测建模的R方为: ",r2_score(test_labels, y_predict))
# print("多分类预测的报告: \n",classification_report(y_predict, test_labels))
多分类预测建模的精度acc为:  0.780053428317008
多分类预测建模的R方为:  0.4157152870789089

预测的精度为78%左右

预测结果统计

根据预测结果和真实值,从头实现精度的计算,不调用任何相关模块。

In [36]:

import pandas as pd

df = pd.DataFrame({"y_test":test_labels,
                   "y_predict":y_predict
                  })

df.head()

Out[36]:

y_testy_predict
034
11010
211
344
4413

In [37]:

df["result"] = (df["y_test"] == df["y_predict"])  # 判断相等为True  否则为False
df.head()

Out[37]:

y_testy_predictresult
034False
11010True
211True
344True
4413False

统计不同原标签的正确预测数目:sum求和只对True(变成1),False为0

In [38]:

df1 = df.groupby("y_test")["result"].sum()
df1.head(10)

Out[38]:

y_test
0      7
1     84
2     12
3    744
4    437
5      0
6     12
7      1
8     23
9     16
Name: result, dtype: int64

In [39]:

df1.sort_values(ascending=False).head(10)

Out[39]:

y_test
3     744
4     437
19     96
1      84
16     75
11     68
20     34
10     25
8      23
13     22
Name: result, dtype: int64

可以看到第3、4、19类别是预测准确最多的。原始数据中每个类别的数目:

In [40]:

df2 = df["y_test"].value_counts().sort_index()
df2.head(10)

Out[40]:

0     12
1    105
2     20
3    813
4    474
5      5
6     14
7      3
8     38
9     25
Name: y_test, dtype: int64

In [41]:

df1.values

Out[41]:

array([  7,  84,  12, 744, 437,   0,  12,   1,  23,  16,  25,  68,   0,
        22,   0,   1,  75,   2,  12,  96,  34,  18,   0,   3,   4,  20,
         4,   1,   1,   0,   6,   2,   6,   1,   5,   0,   2,   0,   0,
         0,   0,   1,   0,   3,   4,   0], dtype=int64)

In [42]:

# 将df1-df2合并

df3 = pd.DataFrame({"predict":df1.values,  # 预测正确数目
                   "true":df2.values})  # 原数据数目
df3.head()

Out[42]:

predicttrue
0712
184105
21220
3744813
4437474

In [43]:

df3["precision"] = df3["predict"] / df3["true"]
df3.head(10)

Out[43]:

predicttrueprecision
07120.583333
1841050.800000
212200.600000
37448130.915129
44374740.921941
5050.000000
612140.857143
7130.333333
823380.605263
916250.640000

可以和分类报告中的precision进行对比,结果是一致的(除去小数位问题)

In [44]:

print("多分类预测的报告: \n",classification_report(y_predict, test_labels))

# 结果(部分)
多分类预测的报告: 
               precision    recall  f1-score   support

           0       0.58      0.88      0.70         8
           1       0.80      0.60      0.68       141
           2       0.60      0.86      0.71        14
           3       0.92      0.94      0.93       788
           4       0.92      0.75      0.82       586
           5       0.00      0.00      0.00         0
           6       0.86      0.80      0.83        15
           7       0.33      1.00      0.50         1
           8       0.61      0.70      0.65        33
           9       0.64      0.84      0.73        19
          10       0.83      0.81      0.82        31
          11       0.82      0.51      0.63       133
          12       0.00      0.00      0.00         2
          13       0.59      0.61      0.60        36
          14       0.00      0.00      0.00         0
          15       0.11      0.50      0.18         2
          16       0.76      0.72      0.74       104
          17       0.17      1.00      0.29         2
          18       0.60      0.60      0.60        20

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

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

相关文章

180页的Python完全版电子书

大家好,我是涛哥。 Python学习有很多方式,可以从基础一步步看语法, 可以从案例一步步学习,本篇内容就是通过案例进行讲解,方便大家一步一步进行学习实战。 整个内容经过几个月总结《Python之路2.0.pdf》&#xff0c…

基于 Python 的音乐流派分类

音乐就像一面镜子,它可以告诉人们很多关于你是谁,你关心什么,不管你喜欢与否。我们喜欢说“you are what you stream” - Spotify Spotify 拥有 260 亿美元的净资产,是如今很受欢迎的音乐流媒体平台。它目前在其数据库中拥有数百…

Java拓展--空间复杂度和时间复杂度

空间复杂度和时间复杂度 文章目录 空间复杂度和时间复杂度空间复杂度时间复杂度**评价排序算法****时间频度****什么是时间频度****忽略常数项****忽略低次项****忽略系数** **时间复杂度****什么是时间复杂度****计算时间复杂度的方法****常见的时间复杂度** **常见的时间复杂…

正中优配:证券融资融券是什么意思?

证券融资融券(简称“融资融券”)是一种股票出资办法,是指出资者经过融券生意和融资生意来进行股票出资。它在出资商场上具有重要的作用,因为经过这种办法,出资者能够使用假贷资金进行股票生意,能够进步出资…

腾讯云4核8G服务器选CVM还是轻量比较好?价格对比

腾讯云4核8G云服务器可以选择轻量应用服务器或CVM云服务器标准型S5实例,轻量4核8G12M服务器446元一年,CVM S5云服务器935元一年,相对于云服务器CVM,轻量应用服务器性价比更高,轻量服务器CPU和CVM有区别吗?性…

23062C++QTday4

仿照string类&#xff0c;完成myString 类 代码&#xff1a; #include <iostream> #include <cstring> using namespace std; class myString {private:char *str; //记录c风格的字符串int size; //记录字符串的实际长度public://无参构造my…

华为云云耀云服务器L实例评测 | 由于自己原因导致MySQL数据库被攻击 【更新中。。。】

目录 引出起因&#xff08;si因&#xff09;解决报错诶嘿&#xff0c;连上了 不出意外&#xff0c;就出意外了打开数据库what&#xff1f;&#xff1f;&#xff1f; 找华为云求助教训&#xff1a;备份教训&#xff1a;密码 解决1.改密码2.新建一个MySQL&#xff0c;密码设置复杂…

Android T 窗口层级其三 —— 层级结构树添加窗口

文章目录 序节点添加Task以DefaultTaskDisplayArea为父节点以Task为父节点 ActivityRecordWindowTokenWindowState以WindowToken为父节点以ActivityRecord为父节点 小结调用场景添加差异 流程分析添加log堆栈打印流程LauncherStatusBar 序 尚未添加窗口的层级结构树&#xff0…

前端该了解的网络知识

网络 前端开发需要了解的网络知识 URL URL(uniform resource locator,统一资源定位符)用于定位网络服务. URL是一个固定格式的字符串 它表达了: 从网络中哪台计算机(domain)中的哪个服务(port),获取服务器上资源的路径(path),以及要用什么样的协议通信(schema). 注意: 当…

探索Netty的FuturePromise

Netty—Future&Promise 一、JDK原生 Future二、Netty包下的 Future三、Promise1、使用Promise同步获取结果2、使用Promise异步获取结果.3、使用Promise同步获取异常 - sync & get4、使用Promise同步获取异常 - await5、使用Promise异步获取异常 在异步处理时&#xff0…

颜色代码对照表

颜色代码对照表 各颜色代码: 1 白色 #FFFFFF 2 红色 #FF0000 3 绿色 #00FF00 4 蓝色 #0000FF 5 牡丹红 #FF00FF 6 青色 #00FFFF 7 黄色 #FFFF00 8 黑色 #000000 9 海蓝 #70DB93 …

出行类APP商业化路径解决方案

当下市场主流的商业化路径和方法相比于之前区别不大&#xff0c;开发者们都是在现有商业化体系下&#xff0c;制定更加详细、优质的策略&#xff0c;以期获得更高利益。 出行类App用户结构分析 年龄层次&#xff1a;出行类App用户的年龄分布比较广泛&#xff0c;主要集中在20…

商品防伪查询溯源小程序开发源码

企业商家在销售商品的过程中被人仿冒产品以次充好损害公司名声和影响产品销量是很多企业的痛点。我们基于次帮助企业开发了一款商品防伪溯源查询小程序&#xff0c;解决企业痛点&#xff0c;酿造更好的经商坏境。 核心功能&#xff1a; 我们采用一物一码的逻辑&#xff0c;可…

【网络基础】——HTTPS

目录 HTTPS背景知识 HTTPS是什么&#xff1f; 加密解密 为什么要加密 常见的加密方式 对称加密 非对称加密 数据摘要&&数据指纹 数字签名 HTTPS工作过程探究 方案1&#xff1a;只使用对称加密 方案2&#xff1a;只使用非对称加密 方案3&#xff1a;双方…

day37 线程

一、线程安全 二、多线程并发的安全问题 当多个线程并发操作同一临界资源 由于线程切换实际不确定 导致操作顺序出现混乱 产生的程序bug 严重时出现系统瘫痪 临界资源 &#xff1a;操作该资源的完整流程同一时间只能被单一线程操作的资源 多线程并发会出现的各种问题、 如…

IT运维:使用数据分析平台监控奇安信

监控目标 本文基于鸿鹄2.10.0版本。 ●监控奇安信日志类型分布 ●监控奇安信攻击行为、分析攻击类型 ●监控奇安信攻击来源情况 操作步骤 数据导入 1、创建数据集&#xff0c;如使用已经存在的数据集&#xff0c;可跳过此步骤 数据集名称&#xff1a;qax_syslog&#xff08;仪表…

管理类联考——数学——汇总篇——知识点突破——应用题——鸡兔同笼

⛲️ 一、考点讲解 第一鸡兔同笼问题 若已知脚数之和及鸡兔总数&#xff0c;求各多少只&#xff1a; 假设全都是鸡&#xff0c;则有 兔数 ( 实际脚数 − 2 鸡兔总数 ) ( 4 − 2 ) 兔数(实际脚数-2鸡兔总数)(4-2) 兔数(实际脚数−2鸡兔总数)(4−2) 假设全都是兔&#xff0…

Python 基础知识:语法、数据类型和控制结构

推荐&#xff1a;使用 NSDT场景编辑器 快速搭建3D应用场景 如果开发和环境中已安装 Python&#xff0c;请启动 Python REPL 和代码。或者&#xff0c;如果您想跳过安装并立即开始编码&#xff0c;我建议您前往Google Colab并一起编码。 你好&#xff0c;Python&#xff01; 在…

【算法日志】单调栈: 单调栈简介及其应用

代码随想录刷题60Day 目录 单调栈简介 单调栈的应用 下次更高温 下一个更大元素1 下一个更大元素2 接雨水 柱状图中最大矩形 单调栈简介 单调栈&#xff08;Monotonic Stack&#xff09;是一种特殊的栈数据结构&#xff0c;它满足元素的单调性&#xff0c;这种单调性需…

vue3使用el-form实现登录、注册功能,且进行表单验证(Element Plus中的el-form)

简介&#xff1a;Element Plus 中的 el-form 是一个表单组件&#xff0c;用于快速构建表单并进行数据校验。它提供了丰富的表单元素和验证规则&#xff0c;使表单开发变得更加简单和高效。可以搭配el-dialog实现当前页面的登录、注册页 &#xff0c;这两天在vue3中用到了表单登…