构建的集成分类器,它通常比任何单个成员的预测性能都要好。
把不同的分类算法及其各自相应的权重组合起来。目标是建立一个更强大的超级分类器,以平衡单个分类器在特定数据集上的弱点。

import numpy as np
import matplotlib.pyplot as plt
from sklearn.base import BaseEstimator
from sklearn.base import ClassifierMixin
from sklearn.preprocessing import LabelEncoder
# from sklearn.externals import six
import six
import sys
sys.modules['sklearn.externals.six'] = sixfrom sklearn.base import clone
from sklearn.pipeline import _name_estimators
import operator
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.pipeline import Pipeline
from sklearn.model_selection import cross_val_score
from sklearn.metrics import roc_curve
from sklearn.metrics import auc
from itertools import product
from sklearn.model_selection import GridSearchCV# 用父类 BaseEstimator和ClassifierMixin轻而易举地获得了一些基本功能,
# 这包括设置和返回分类器参数的get_params和set_params方法,
# 以及计算预测准确度的score方法。
class MajorityVoteClassifier(BaseEstimator, ClassifierMixin):""" A majority vote ensemble classifierParameters----------classifiers : array-like, shape = [n_classifiers]Different classifiers for the ensemblevote : str, {'classlabel', 'probability'} (default='label')If 'classlabel' the prediction is based on the argmax ofclass labels. Else if 'probability', the argmax ofthe sum of probabilities is used to predict the class label(recommended for calibrated classifiers).weights : array-like, shape = [n_classifiers], optional (default=None)If a list of `int` or `float` values are provided, the classifiersare weighted by importance; Uses uniform weights if `weights=None`."""def __init__(self, classifiers, vote='classlabel', weights=None):self.classifiers = classifiers# 使用_name_estimators函数访问集成分类器中每个成员分类器的参数self.named_classifiers = {key: value for key, valuein _name_estimators(classifiers)}# print("_name_estimators(classifiers):", _name_estimators(classifiers))# print(self.named_classifiers)self.vote = voteself.weights = weightsdef fit(self, X, y):""" Fit classifiers.Parameters----------X : {array-like, sparse matrix}, shape = [n_samples, n_features]Matrix of training samples.y : array-like, shape = [n_samples]Vector of target class labels.Returns-------self : object"""if self.vote not in ('probability', 'classlabel'):raise ValueError("vote must be 'probability' or 'classlabel'""; got (vote=%r)"% self.vote)if self.weights and len(self.weights) != len(self.classifiers):raise ValueError('Number of classifiers and weights must be equal''; got %d weights, %d classifiers'% (len(self.weights), len(self.classifiers)))# Use LabelEncoder to ensure class labels start with 0, which# is important for np.argmax call in self.predictself.lablenc_ = LabelEncoder()self.lablenc_.fit(y)self.classes_ = self.lablenc_.classes_self.classifiers_ = []for clf in self.classifiers:fitted_clf = clone(clf).fit(X, self.lablenc_.transform(y))self.classifiers_.append(fitted_clf)return selfdef predict(self, X):""" Predict class labels for X.Parameters----------X : {array-like, sparse matrix}, shape = [n_samples, n_features]Matrix of training samples.Returns----------maj_vote : array-like, shape = [n_samples]Predicted class labels."""if self.vote == 'probability':maj_vote = np.argmax(self.predict_proba(X), axis=1)# print("maj_vote:", maj_vote)else:  # 'classlabel' vote#  Collect results from clf.predict calls# np.array (默认情况下)将会copy该对象,而 np.asarray 除非必要,否则不会copy该对象。predictions = np.asarray([clf.predict(X) for clf in self.classifiers_]).T# print("predictions:", predictions)# 将arr数组的每一个元素经过func函数变换形成的一个新数组maj_vote = np.apply_along_axis(lambda x: np.argmax(np.bincount(x, weights=self.weights)),axis=1,arr=predictions)# print("转化前maj_vote:", maj_vote)maj_vote = self.lablenc_.inverse_transform(maj_vote)# print("转化后的maj_vote:", maj_vote)return maj_votedef predict_proba(self, X):""" Predict class probabilities for X.Parameters----------X : {array-like, sparse matrix}, shape = [n_samples, n_features]Training vectors, where n_samples is the number of samples andn_features is the number of features.Returns----------avg_proba : array-like, shape = [n_samples, n_classes]Weighted average probability for each class per sample."""probas = np.asarray([clf.predict_proba(X) for clf in self.classifiers_])avg_proba = np.average(probas, axis=0, weights=self.weights)# print("probas:", probas)# print("avg_proba:", avg_proba)return avg_probadef get_params(self, deep=True):""" Get classifier parameter names for GridSearch"""if not deep:return super(MajorityVoteClassifier, self).get_params(deep=False)else:out = self.named_classifiers.copy()for name, step in six.iteritems(self.named_classifiers):for key, value in six.iteritems(step.get_params(deep=True)):out['%s__%s' % (name, key)] = valuereturn outiris = datasets.load_iris()
X, y = iris.data[50:, [1, 2]], iris.target[50:]
# print("y:", y)
le = LabelEncoder()
y = le.fit_transform(y)
# print("y:", y)X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=0.5,random_state=1,stratify=y)clf1 = LogisticRegression(penalty='l2', C=0.001, random_state=1)
'''
criterion这个参数正是用来决定不纯度的计算方法。sklearn提供了两种选择:
1)输入”entropy“,使用信息熵
2)输入”gini“,使用基尼系数
'''
clf2 = DecisionTreeClassifier(max_depth=1, criterion='entropy', random_state=0)# metric:用于树的距离度量。默认'minkowski与P = 2(即欧氏度量)
clf3 = KNeighborsClassifier(n_neighbors=1, p=2, metric='minkowski')pipe1 = Pipeline([['sc', StandardScaler()],['clf', clf1]])
pipe3 = Pipeline([['sc', StandardScaler()],['clf', clf3]])clf_labels = ['Logistic regression', 'Decision tree', 'KNN']# 在将它们构建成集成分类器之前,先通过对训练集进行10次交叉验证以评估每个分类器模型的性能
# print('10-fold cross validation:\n')
# for clf, label in zip([pipe1, clf2, pipe3], clf_labels):
#     scores = cross_val_score(estimator=clf,
#                              X=X_train,
#                              y=y_train,
#                              cv=10,
#                              scoring='roc_auc')
#     print("ROC AUC: %0.2f (+/- %0.2f) [%s]" % (scores.mean(), scores.std(), label))# Majority Rule (hard) Votingmv_clf = MajorityVoteClassifier(classifiers=[pipe1, clf2, pipe3])
y_pred_ = mv_clf.fit(X_train, y_train).predict(X_test)
print("y_pred_:", y_pred_)
print("get_params():", mv_clf.get_params())
print("get_params(deep=False):", mv_clf.get_params(deep=False))clf_labels += ['Majority voting']
all_clf = [pipe1, clf2, pipe3, mv_clf]# 可以看到各个分类器的MajorityVotingClassifier的性能已经在有10个分区的交叉验证评估上得到改善
# for clf, label in zip(all_clf, clf_labels):
#     scores = cross_val_score(estimator=clf,
#                              X=X_train,
#                              y=y_train,
#                              cv=10,
#                              scoring='roc_auc')
#     print("ROC AUC: %0.2f (+/- %0.2f) [%s]"
#           % (scores.mean(), scores.std(), label))# # Evaluating and tuning the ensemble classifier
# ROC结果图
# 基于测试数据来计算ROC曲线,以检查MajorityVoteClassifier对未见过的数据是否泛化良好。
colors = ['black', 'orange', 'blue', 'green']
linestyles = [':', '--', '-.', '-']
for clf, label, clr, ls in zip(all_clf, clf_labels, colors, linestyles):# assuming the label of the positive class is 1y_pred = clf.fit(X_train, y_train).predict_proba(X_test)[:, 1]fpr, tpr, thresholds = roc_curve(y_true=y_test,y_score=y_pred)roc_auc = auc(x=fpr, y=tpr)  # 计算曲线下面积plt.plot(fpr, tpr,color=clr,linestyle=ls,label='%s (auc = %0.2f)' % (label, roc_auc))plt.legend(loc='lower right')
plt.plot([0, 1], [0, 1],linestyle='--',color='gray',linewidth=2)plt.xlim([-0.1, 1.1])
plt.ylim([-0.1, 1.1])
plt.grid(alpha=0.5)
plt.xlabel('False positive rate (FPR)')
plt.ylabel('True positive rate (TPR)')#plt.savefig('images/07_04', dpi=300)
plt.show()# 看看集成分类器决策区域
# 集成分类器决策区域似乎是单个分类器决 策区域的混合体
sc = StandardScaler()
X_train_std = sc.fit_transform(X_train)all_clf = [pipe1, clf2, pipe3, mv_clf]x_min = X_train_std[:, 0].min() - 1
x_max = X_train_std[:, 0].max() + 1
y_min = X_train_std[:, 1].min() - 1
y_max = X_train_std[:, 1].max() + 1xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.1),np.arange(y_min, y_max, 0.1))f, axarr = plt.subplots(nrows=2, ncols=2,sharex='col',sharey='row',figsize=(7, 5))for idx, clf, tt in zip(product([0, 1], [0, 1]),all_clf, clf_labels):clf.fit(X_train_std, y_train)Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])Z = Z.reshape(xx.shape)axarr[idx[0], idx[1]].contourf(xx, yy, Z, alpha=0.3)axarr[idx[0], idx[1]].scatter(X_train_std[y_train == 0, 0],X_train_std[y_train == 0, 1],c='blue',marker='^',s=50)axarr[idx[0], idx[1]].scatter(X_train_std[y_train == 1, 0],X_train_std[y_train == 1, 1],c='green',marker='o',s=50)axarr[idx[0], idx[1]].set_title(tt)# plt.savefig('images/07_05', dpi=300)
plt.show()
# 访问单个分类器的属性
print(mv_clf.get_params())# 通过网格搜索来优化逻辑回归分类器的逆正则化 参数C和决策树深度
params = {'decisiontreeclassifier__max_depth': [1, 2],'pipeline-1__clf__C': [0.001, 0.1, 100.0]}grid = GridSearchCV(estimator=mv_clf,param_grid=params,cv=10,scoring='roc_auc')
grid.fit(X_train, y_train)# 网格搜索完成后,可以列出不同的超参数值组合,以及通过10个分区的交叉验证计算所获得ROC AUC的平均评分
for r, _ in enumerate(grid.cv_results_['mean_test_score']):print("%0.3f +/- %0.2f %r"% (grid.cv_results_['mean_test_score'][r],grid.cv_results_['std_test_score'][r] / 2.0,grid.cv_results_['params'][r]))print('Best parameters: %s' % grid.best_params_)
print('Accuracy: %.2f' % grid.best_score_)

运行结果:
y_pred_: [0 0 0 0 0 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0
1 1 0 1 0 0 1 0 0 1 0 0 0]
get_params(): {‘pipeline-1’: Pipeline(steps=[[‘sc’, StandardScaler()],
[‘clf’, LogisticRegression(C=0.001, random_state=1)]]), ‘decisiontreeclassifier’: DecisionTreeClassifier(criterion=‘entropy’, max_depth=1, random_state=0), ‘pipeline-2’: Pipeline(steps=[[‘sc’, StandardScaler()],
[‘clf’, KNeighborsClassifier(n_neighbors=1)]]), ‘pipeline-1__memory’: None, ‘pipeline-1__steps’: [[‘sc’, StandardScaler()], [‘clf’, LogisticRegression(C=0.001, random_state=1)]], ‘pipeline-1__verbose’: False, ‘pipeline-1__sc’: StandardScaler(), ‘pipeline-1__clf’: LogisticRegression(C=0.001, random_state=1), ‘pipeline-1__sc__copy’: True, ‘pipeline-1__sc__with_mean’: True, ‘pipeline-1__sc__with_std’: True, ‘pipeline-1__clf__C’: 0.001, ‘pipeline-1__clf__class_weight’: None, ‘pipeline-1__clf__dual’: False, ‘pipeline-1__clf__fit_intercept’: True, ‘pipeline-1__clf__intercept_scaling’: 1, ‘pipeline-1__clf__l1_ratio’: None, ‘pipeline-1__clf__max_iter’: 100, ‘pipeline-1__clf__multi_class’: ‘auto’, ‘pipeline-1__clf__n_jobs’: None, ‘pipeline-1__clf__penalty’: ‘l2’, ‘pipeline-1__clf__random_state’: 1, ‘pipeline-1__clf__solver’: ‘lbfgs’, ‘pipeline-1__clf__tol’: 0.0001, ‘pipeline-1__clf__verbose’: 0, ‘pipeline-1__clf__warm_start’: False, ‘decisiontreeclassifier__ccp_alpha’: 0.0, ‘decisiontreeclassifier__class_weight’: None, ‘decisiontreeclassifier__criterion’: ‘entropy’, ‘decisiontreeclassifier__max_depth’: 1, ‘decisiontreeclassifier__max_features’: None, ‘decisiontreeclassifier__max_leaf_nodes’: None, ‘decisiontreeclassifier__min_impurity_decrease’: 0.0, ‘decisiontreeclassifier__min_impurity_split’: None, ‘decisiontreeclassifier__min_samples_leaf’: 1, ‘decisiontreeclassifier__min_samples_split’: 2, ‘decisiontreeclassifier__min_weight_fraction_leaf’: 0.0, ‘decisiontreeclassifier__presort’: ‘deprecated’, ‘decisiontreeclassifier__random_state’: 0, ‘decisiontreeclassifier__splitter’: ‘best’, ‘pipeline-2__memory’: None, ‘pipeline-2__steps’: [[‘sc’, StandardScaler()], [‘clf’, KNeighborsClassifier(n_neighbors=1)]], ‘pipeline-2__verbose’: False, ‘pipeline-2__sc’: StandardScaler(), ‘pipeline-2__clf’: KNeighborsClassifier(n_neighbors=1), ‘pipeline-2__sc__copy’: True, ‘pipeline-2__sc__with_mean’: True, ‘pipeline-2__sc__with_std’: True, ‘pipeline-2__clf__algorithm’: ‘auto’, ‘pipeline-2__clf__leaf_size’: 30, ‘pipeline-2__clf__metric’: ‘minkowski’, ‘pipeline-2__clf__metric_params’: None, ‘pipeline-2__clf__n_jobs’: None, ‘pipeline-2__clf__n_neighbors’: 1, ‘pipeline-2__clf__p’: 2, ‘pipeline-2__clf__weights’: ‘uniform’}
get_params(deep=False): {‘classifiers’: [Pipeline(steps=[[‘sc’, StandardScaler()],
[‘clf’, LogisticRegression(C=0.001, random_state=1)]]), DecisionTreeClassifier(criterion=‘entropy’, max_depth=1, random_state=0), Pipeline(steps=[[‘sc’, StandardScaler()],
[‘clf’, KNeighborsClassifier(n_neighbors=1)]])], ‘vote’: ‘classlabel’, ‘weights’: None}
{‘pipeline-1’: Pipeline(steps=[(‘sc’, StandardScaler()),
[‘clf’, LogisticRegression(C=0.001, random_state=1)]]), ‘decisiontreeclassifier’: DecisionTreeClassifier(criterion=‘entropy’, max_depth=1, random_state=0), ‘pipeline-2’: Pipeline(steps=[(‘sc’, StandardScaler()),
[‘clf’, KNeighborsClassifier(n_neighbors=1)]]), ‘pipeline-1__memory’: None, ‘pipeline-1__steps’: [(‘sc’, StandardScaler()), [‘clf’, LogisticRegression(C=0.001, random_state=1)]], ‘pipeline-1__verbose’: False, ‘pipeline-1__sc’: StandardScaler(), ‘pipeline-1__clf’: LogisticRegression(C=0.001, random_state=1), ‘pipeline-1__sc__copy’: True, ‘pipeline-1__sc__with_mean’: True, ‘pipeline-1__sc__with_std’: True, ‘pipeline-1__clf__C’: 0.001, ‘pipeline-1__clf__class_weight’: None, ‘pipeline-1__clf__dual’: False, ‘pipeline-1__clf__fit_intercept’: True, ‘pipeline-1__clf__intercept_scaling’: 1, ‘pipeline-1__clf__l1_ratio’: None, ‘pipeline-1__clf__max_iter’: 100, ‘pipeline-1__clf__multi_class’: ‘auto’, ‘pipeline-1__clf__n_jobs’: None, ‘pipeline-1__clf__penalty’: ‘l2’, ‘pipeline-1__clf__random_state’: 1, ‘pipeline-1__clf__solver’: ‘lbfgs’, ‘pipeline-1__clf__tol’: 0.0001, ‘pipeline-1__clf__verbose’: 0, ‘pipeline-1__clf__warm_start’: False, ‘decisiontreeclassifier__ccp_alpha’: 0.0, ‘decisiontreeclassifier__class_weight’: None, ‘decisiontreeclassifier__criterion’: ‘entropy’, ‘decisiontreeclassifier__max_depth’: 1, ‘decisiontreeclassifier__max_features’: None, ‘decisiontreeclassifier__max_leaf_nodes’: None, ‘decisiontreeclassifier__min_impurity_decrease’: 0.0, ‘decisiontreeclassifier__min_impurity_split’: None, ‘decisiontreeclassifier__min_samples_leaf’: 1, ‘decisiontreeclassifier__min_samples_split’: 2, ‘decisiontreeclassifier__min_weight_fraction_leaf’: 0.0, ‘decisiontreeclassifier__presort’: ‘deprecated’, ‘decisiontreeclassifier__random_state’: 0, ‘decisiontreeclassifier__splitter’: ‘best’, ‘pipeline-2__memory’: None, ‘pipeline-2__steps’: [(‘sc’, StandardScaler()), [‘clf’, KNeighborsClassifier(n_neighbors=1)]], ‘pipeline-2__verbose’: False, ‘pipeline-2__sc’: StandardScaler(), ‘pipeline-2__clf’: KNeighborsClassifier(n_neighbors=1), ‘pipeline-2__sc__copy’: True, ‘pipeline-2__sc__with_mean’: True, ‘pipeline-2__sc__with_std’: True, ‘pipeline-2__clf__algorithm’: ‘auto’, ‘pipeline-2__clf__leaf_size’: 30, ‘pipeline-2__clf__metric’: ‘minkowski’, ‘pipeline-2__clf__metric_params’: None, ‘pipeline-2__clf__n_jobs’: None, ‘pipeline-2__clf__n_neighbors’: 1, ‘pipeline-2__clf__p’: 2, ‘pipeline-2__clf__weights’: ‘uniform’}
0.983 +/- 0.02 {‘decisiontreeclassifier__max_depth’: 1, ‘pipeline-1__clf__C’: 0.001}
0.983 +/- 0.02 {‘decisiontreeclassifier__max_depth’: 1, ‘pipeline-1__clf__C’: 0.1}
0.967 +/- 0.05 {‘decisiontreeclassifier__max_depth’: 1, ‘pipeline-1__clf__C’: 100.0}
0.983 +/- 0.02 {‘decisiontreeclassifier__max_depth’: 2, ‘pipeline-1__clf__C’: 0.001}
0.983 +/- 0.02 {‘decisiontreeclassifier__max_depth’: 2, ‘pipeline-1__clf__C’: 0.1}
0.967 +/- 0.05 {‘decisiontreeclassifier__max_depth’: 2, ‘pipeline-1__clf__C’: 100.0}
Best parameters: {‘decisiontreeclassifier__max_depth’: 1, ‘pipeline-1__clf__C’: 0.001}
Accuracy: 0.98

备注:scikit-learn实现了更复杂的多数票分类器。可以从scikit-learn 0.17 或者更新版本中找到sklearn.ensemble.VotingClassifier。

查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. JavaScript打印直角三角形、等腰三角形和菱形

    一.打印直角三角形 js代码&#xff1a; <script>for(var i0;i<4;i){var s"";for(var k0;k<2*i1;k){s"*";}console.log(s);}</script>效果图&#xff1a; 二.打印等腰三角形 js代码&#xff1a; <script>for(var i0;i<4;i…...

    2024/4/24 21:03:45
  2. java面向对象封装

    java面向对象封装 面向对象的思想:面向过程思想就是首先搞清楚我们要做什么&#xff0c;然后分析怎么做&#xff0c;最后再用代码来实现。随着需求越来越多&#xff0c;发现面对每一个步骤就很麻烦。这时就开始思索&#xff0c;能不能把这些步骤和功能进行封装&#xff0c;封装…...

    2024/4/24 21:03:43
  3. Apache日志分割

    日志分割 随着网站的访问量越来越大&#xff0c;默认情况下Apache服务器产生单个日志也会越来越大&#xff0c;不对日志分割&#xff0c;那么日志文件占用磁盘会越来越大&#xff0c;如果直接删除会丢失很多比较宝贵的信息&#xff0c;而这些日志可以用来访问分析&#xff0c;…...

    2024/5/2 15:47:48
  4. QT线程 Emit、Sgnals、Slot详细解释

    前言&#xff1a; 转载请附上连接,本帖原创请勿照抄。 信号和槽机制是 QT 的核心机制&#xff0c;要精通 QT 编程就必须对信号和槽有所了解。信号和槽是一种高级接口&#xff0c;应用于对象之间的通信...... 这篇文章给大家讲解最主要的三个点&#xff0c;其它的一大堆内容请…...

    2024/5/2 6:43:55
  5. python自定义装饰器的情况(详解)

    关于函数定义的单一装饰器一般的通用装饰器多个装饰器的使用带有参数的装饰器类装饰器 这是装饰器的自定义和内部机制一些初识 ***先强调装饰器的要求便是 不改变原来的函数代码装饰器就一个函数引用参数不改变调用方式*** 我先介绍一些闭包&#xff0c;因为装饰器也是基于闭…...

    2024/4/24 21:03:42
  6. git使用技巧及常见问题汇总(身为码农的你不可缺少的技能)

    在gitlab上新建一个project后&#xff0c;有如下教程提示&#xff1a; 1、Git global setup &#xff08;初始设置&#xff0c;设置登录名和密码&#xff09; git config --global user.name "***" git config --global user.email "***stu.ouc.edu.cn"2…...

    2024/4/24 21:03:39
  7. 12_01.【Java】JDBC概述

    使用JDBC技术可以便捷的操作各种主流数据库。大部分应用程序都是使用数据库存储数据的&#xff0c;通过JDBC技术&#xff0c;既可以根据指定条件查询数据库中的数据&#xff0c;又可以对数据库中的数据进行添加、删除、修改等操作。 本文主要讲解使用JDBC操作MySQL数据库的知识…...

    2024/4/24 21:03:38
  8. springboot源码学习1

    占位...

    2024/4/24 21:03:44
  9. Python基础学习之6.Python列表

    文章目录1.序列&#xff08;sequence&#xff09;1.1 基本概念1.2序列的分类1.3 列表(list)1.4 切⽚1.5 通⽤操作1.6 修改列表1.7 列表的⽅法1.8 for和range函数1.序列&#xff08;sequence&#xff09; 1.1 基本概念 - 序列是Python中最基本的⼀种数据结构。序列⽤于保存⼀组…...

    2024/5/2 9:52:22
  10. 温度显示、设定及报警系统设计

    温度显示、设定及报警系统设计&#xff08;我是菜鸟&#xff09; 2.1硬件&#xff1a; &#xff08;1&#xff09;选用ST公司的stm32F446RE开发板&#xff1b; &#xff08;2&#xff09;运用stm32F446RE内部温度传感器采集温度信号&#xff1b; &#xff08;3&#xff09;由P…...

    2024/3/23 1:46:33
  11. intellij过期打不开了!求大佬帮忙,谢谢!!

    intellij2020.2.3之前激活过&#xff0c;用插件激活到2089年了&#xff0c;但是今天强制关机之后再开机&#xff0c;就提示过期了&#xff0c;请问这种情况怎么才能不卸载重新激活呀&#xff0c;谢谢&#xff01;...

    2024/4/17 23:20:39
  12. display:flex属性 justify-content: space-between和flex-flow:wrap一起使用的问题

    .wrap {width: 400px;display:flex; /*弹性盒子*/justify-content: space-between; /*两端对齐&#xff0c;子元素之间有间隙*/flex-flow: row wrap;/*子元素溢出父容器时换行*/ } span {width: 100px;background-color: green;color:#fff;border-radius: 5px;margin-top: 10…...

    2024/3/23 1:46:30
  13. The Tomcat connector configured to listen on port 1804 failed to start. The port——执行spring-boot程序是报错

    执行spring-boot程序是报错 错误过程&#xff1a; ***************************APPLICATION FAILED TO START***************************Description:The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the conn…...

    2024/3/23 1:46:28
  14. linux排查网络常用命令

    nc 网络连通性测试和端口扫描 nc -l 80 & 包含&后台监听某个端口&#xff0c;监听是tcp端口 nc -vz -w 2 127.0.0.1 80 -v可视化&#xff0c;-z扫描时不发送数据&#xff0c;-w超时几秒&#xff0c;后面跟数字 -u扫描连接udp端口 nc -ul 9999 启动一个udp的端口监…...

    2024/4/24 5:34:33
  15. 06-图1 列出连通集

    06-图1 列出连通集 题意&#xff1a;给出一个无向图&#xff0c;分别用dfs和bfs找出图中的连通块。连通块按从小到大的顺序输出。 思路&#xff1a; dfs和bfs遍历一遍图可以找出一个连通块&#xff0c;只需分别以每个点为起点进行dfs或bfs&#xff0c;就能找出所有连通块。因…...

    2024/4/11 0:25:42
  16. 剑指Offer_编程题 9.变态跳台阶

    题目描述 一只青蛙一次可以跳上1级台阶&#xff0c;也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。 感谢alan_gaohaodong大神的详细解法&#xff0c;传送门https://blog.csdn.net/alan_gaohaodong/article/details/80987412 class Solutio…...

    2024/3/28 1:30:34
  17. Linux初学第十五天<网络编程一、网络编程概念>

    一、概念 之前我们学过的管道、消息队列、共享内存和信号等&#xff0c;它们都是基于内核来工作的&#xff0c;只能让本机上的进程之间通讯&#xff0c;无法做到多机通讯。多机通讯就是电脑和电脑之间&#xff0c;或者手机和电脑之前的通讯。想要做到不同设备间的通讯&#xff…...

    2024/3/23 9:06:23
  18. Linux常见系统管理类命令

    Linux常见系统管理类命令ls&#xff1a;显示指定工作目录下内容的命令pwd&#xff1a;显示当前工作目录cd&#xff1a;改变当前工作目录date&#xff1a;显示或修改时间与日期passwd&#xff1a;设置用户密码su&#xff1a;切换用户身份w&#xff1a;显示目前登入系统的用户信息…...

    2024/4/28 6:14:28
  19. 【C++】实现大数相加

    引言: 在我们学习了加法运算之后&#xff0c;了解了int型最大可以表示到2的32次方&#xff0c;但是若要计算更大的数呢&#xff1f;&#xff1f; 解法&#xff1a; 我们利用string来储存数字&#xff0c;string可以存放很多字符&#xff0c;而每一个数字都有对应的ASCII值&…...

    2024/3/23 9:06:22
  20. Linux系统启动原理及故障排除

    实战-当 MBR 引导记录损坏后-重装 grub 进行修复centos7 系统启动过程及相关配置文件centos7 系统启动过程当 MBR 引导记录损坏后-重装 grub 进行修复第一步&#xff1a;在 centOS7 下破坏硬盘的前 446 字节&#xff1a;第二步&#xff1a;将 centos7 系统光盘挂载到虚拟机光驱…...

    2024/3/29 2:23:21

最新文章

  1. 【docker】docker compose 搭建私服

    安装 Docker Registry 创建目录 mkdir -pv /usr/local/docker/registrymkdir -pv /usr/local/docker/data 创建 docker-compose.yml文件 进入目录创建docker-compose.yml cd /usr/local/docker/registrytouch docker-compose.yml 编辑docker-compose.yml vim docker-compo…...

    2024/5/2 16:45:29
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. c++类的继承方式

    在 C 中&#xff0c;类的继承方式有三种&#xff1a;公有继承&#xff08;public inheritance&#xff09;、保护继承&#xff08;protected inheritance&#xff09;和私有继承&#xff08;private inheritance&#xff09;。这些继承方式决定了派生类对基类成员的访问权限。 …...

    2024/5/1 9:08:04
  4. C#,简单,精巧,实用的文件夹时间整理工具FolderTime

    点击下载本文软件&#xff08;5积分&#xff09;&#xff1a; https://download.csdn.net/download/beijinghorn/89071073https://download.csdn.net/download/beijinghorn/89071073 百度网盘&#xff08;不需积分&#xff09;&#xff1a; https://pan.baidu.com/s/1FwCsSz…...

    2024/5/1 13:50:22
  5. 416. 分割等和子集问题(动态规划)

    题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义&#xff1a;dp[i][j]表示当背包容量为j&#xff0c;用前i个物品是否正好可以将背包填满&#xff…...

    2024/5/2 11:19:01
  6. 【Java】ExcelWriter自适应宽度工具类(支持中文)

    工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...

    2024/5/2 16:04:58
  7. Spring cloud负载均衡@LoadBalanced LoadBalancerClient

    LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon&#xff0c;直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件&#xff0c;我们讨论Spring负载均衡以Spring Cloud2020之后版本为主&#xff0c;学习Spring Cloud LoadBalance&#xff0c;暂不讨论Ribbon…...

    2024/5/1 21:18:12
  8. TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案

    一、背景需求分析 在工业产业园、化工园或生产制造园区中&#xff0c;周界防范意义重大&#xff0c;对园区的安全起到重要的作用。常规的安防方式是采用人员巡查&#xff0c;人力投入成本大而且效率低。周界一旦被破坏或入侵&#xff0c;会影响园区人员和资产安全&#xff0c;…...

    2024/5/2 9:47:31
  9. VB.net WebBrowser网页元素抓取分析方法

    在用WebBrowser编程实现网页操作自动化时&#xff0c;常要分析网页Html&#xff0c;例如网页在加载数据时&#xff0c;常会显示“系统处理中&#xff0c;请稍候..”&#xff0c;我们需要在数据加载完成后才能继续下一步操作&#xff0c;如何抓取这个信息的网页html元素变化&…...

    2024/5/2 9:47:31
  10. 【Objective-C】Objective-C汇总

    方法定义 参考&#xff1a;https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...

    2024/5/2 6:03:07
  11. 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】

    &#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】&#x1f30f;题目描述&#x1f30f;输入格…...

    2024/5/2 9:47:30
  12. 【ES6.0】- 扩展运算符(...)

    【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数&#xff0…...

    2024/5/1 11:24:00
  13. 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?

    文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕&#xff0c;各大品牌纷纷晒出优异的成绩单&#xff0c;摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称&#xff0c;在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁&#xff0c;多个平台数据都表现出极度异常…...

    2024/5/2 5:31:39
  14. Go语言常用命令详解(二)

    文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令&#xff0c;这些命令可以帮助您在Go开发中进行编译、测试、运行和…...

    2024/5/1 20:22:59
  15. 用欧拉路径判断图同构推出reverse合法性:1116T4

    http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b&#xff0c;我们在 a i a_i ai​ 和 a i 1 a_{i1} ai1​ 之间连边&#xff0c; b b b 同理&#xff0c;则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然&#xff0…...

    2024/5/2 9:47:28
  16. 【NGINX--1】基础知识

    1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息&#xff0c;并安装一些有助于配置官方 NGINX 软件包仓库的软件包&#xff1a; apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...

    2024/5/2 9:47:27
  17. Hive默认分割符、存储格式与数据压缩

    目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限&#xff08;ROW FORMAT&#xff09;配置标准HQL为&#xff1a; ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...

    2024/5/2 0:07:22
  18. 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法

    文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中&#xff0c;传感器和控制器产生大量周…...

    2024/5/2 8:37:00
  19. --max-old-space-size=8192报错

    vue项目运行时&#xff0c;如果经常运行慢&#xff0c;崩溃停止服务&#xff0c;报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中&#xff0c;通过JavaScript使用内存时只能使用部分内存&#xff08;64位系统&…...

    2024/5/2 9:47:26
  20. 基于深度学习的恶意软件检测

    恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞&#xff0c;例如可以被劫持的合法软件&#xff08;例如浏览器或 Web 应用程序插件&#xff09;中的错误。 恶意软件渗透可能会造成灾难性的后果&#xff0c;包括数据被盗、勒索或网…...

    2024/5/2 9:47:25
  21. JS原型对象prototype

    让我简单的为大家介绍一下原型对象prototype吧&#xff01; 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定&#xff0c;每一个构造函数都有一个 prototype 属性&#xff0c;指向另一个对象&#xff0c;所以我们也称为原型对象…...

    2024/5/1 14:33:22
  22. C++中只能有一个实例的单例类

    C中只能有一个实例的单例类 前面讨论的 President 类很不错&#xff0c;但存在一个缺陷&#xff1a;无法禁止通过实例化多个对象来创建多名总统&#xff1a; President One, Two, Three; 由于复制构造函数是私有的&#xff0c;其中每个对象都是不可复制的&#xff0c;但您的目…...

    2024/5/1 11:51:23
  23. python django 小程序图书借阅源码

    开发工具&#xff1a; PyCharm&#xff0c;mysql5.7&#xff0c;微信开发者工具 技术说明&#xff1a; python django html 小程序 功能介绍&#xff1a; 用户端&#xff1a; 登录注册&#xff08;含授权登录&#xff09; 首页显示搜索图书&#xff0c;轮播图&#xff0…...

    2024/5/2 7:30:11
  24. 电子学会C/C++编程等级考试2022年03月(一级)真题解析

    C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...

    2024/5/1 20:56:20
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57