Python实现Logistc回归分类(西瓜数据集、鸢尾花数据集)详解

2023-05-16

文章目录

  • Logistic回归原理讲解
    • 逻辑回归的损失函数
    • 梯度下降
  • 代码实现
    • 西瓜数据集
      • 全代码
    • 鸢尾花(Iris)数据集
      • LogisticModel
        • 全代码
      • 主函数实现
        • 全代码

Logistic回归原理讲解

【声明】 笔者实验之前,参考了助教所提供的另一篇文章内容,自行又额外参考一篇CSDN中的相关文章,之后原理讲解将会基于此基础之上进行,引用其中部分内容进行讲解。
Logistic回归(LR):是一种常用的处理二分类问题的模型,二分类问题中,把结果y分成两个类,正类和负类。因变量y∈{0, 1},0是负类,1是正类。线性回归函数: f ( x ) = θ t x f(x) = \theta^tx f(x)=θtx的输出值在负无穷到正无穷的范围上,并不好区分是正类还是负类。因此引入非线性变换,把线性回归的输出值压缩到(0, 1)之间,Logistic回归就是通过使用Sigmoid函数,也称为逻辑函数(Logistic function) 进行非线性变换:
g ( z ) = 1 1 + e z g(z) = \frac{1}{1+e^z} g(z)=1+ez1
其函数图像如下:
在这里插入图片描述
不难看出Sigmoid函数成像为“S形,它的取值在[0, 1]之间,在远离0的地方函数的值会很快接近0或者1,它的这个特性对于解决二分类问题十分重要。将线性回归函数带入Sigmoid函数得到 g ( θ ) = 1 1 + e θ t x g(\theta) = \frac{1}{1+e^ { \theta^tx} } g(θ)=1+eθtx1

逻辑回归的损失函数

通常提到损失函数,我们不得不提到 代价函数(Cost Function)目标函数 (Object Function)

损失函数(Loss Function) 直接作用于单个样本,用来表达样本的误差

代价函数(Cost Function) 是整个样本集的平均误差,对所有损失函数值的平均

目标函数(Object Function) 是我们最终要优化的函数,也就是代价函数+正则化函数(经验风险+结构风险)

概况来讲,任何能够衡量模型预测出来的值 h ( θ ) h(\theta) h(θ) 与真实值 y 之间的差异的函数都可以叫做代价函数 C ( θ ) C(\theta) C(θ)如果有多个样本,则可以将所有代价函数的取值求均值,记做 J ( θ ) J(\theta) J(θ) 。在逻辑回归中,最常用的是代价函数是交叉熵(Cross Entropy)函数,此时 J ( θ ) 和 C ( θ ) [ c o s t ( θ ) ] J(\theta)和C(\theta)[cost(\theta)] J(θ)C(θ)[cost(θ)]如下:
c o s t ( θ ) = { − l o g ( h θ ( x ) ) y = 1 − l o g ( 1 − h θ ( x ) ) y = 0 cost(\theta)=\begin{equation} \left\{ \begin{array}{lr} -log(h_\theta(x))&y =1 \\ -log(1-h_\theta(x))&y=0 \end{array} \right. \end{equation} cost(θ)={log(hθ(x))log(1hθ(x))y=1y=0
J ( θ ) = 1 m ∑ i = 1 m [ − y i l o g ( h θ ( x i ) ) − ( 1 − y i ) l o g ( 1 − h θ ( x i ) ) ] J(\theta) = \frac{1}{m}\sum\limits^m_{i=1}[-y^{i}log(h_\theta(x^i))-(1-y^i)log(1-h_\theta(x^i))] J(θ)=m1i=1m[yilog(hθ(xi))(1yi)log(1hθ(xi))]
有人可能会问为什么log之前要加负号呢?回忆之前提到的Sigmod函数的值域,只落在(0,1)之间,log在此时都为负数,所以负号用于保证值输出为正值。

梯度下降

我们更新迭代参数 θ \theta θ通过梯度下降的办法,通过对 J ( θ ) J(\theta) J(θ)求导,意在不断寻求最小的损失函数值,优化模型
在这里插入图片描述
可得到
在这里插入图片描述
通过不断迭代即可更新学习参数

代码实现

西瓜数据集

实验的第一个部分是要求根据西瓜书上的西瓜数据集进行模型建立。具体其实只给了两个参数,分别是密度和含糖率,所以直接使用Logistic分类模型即可:

density = np.array([0.697, 0.774, 0.634, 0.608, 0.556, 0.403, 0.481, 0.437, 0.666,
                    0.243, 0.245, 0.343, 0.639, 0.657, 0.360, 0.593, 0.719]).reshape(-1, 1)

sugar_rate = np.array([0.460, 0.376, 0.264, 0.318, 0.215, 0.237, 0.149, 0.211, 0.091,
                       0.267, 0.057, 0.099, 0.161, 0.198, 0.370, 0.042, 0.103]).reshape(-1, 1)

在此我们先给出LogistcModel的初步定义:

class LogisticModel:
    def __init__(self, X, Y, alpha=1, mini=0.0001) -> None:
        self.x = X
        self.y = Y
        self.alpha = alpha#学习率
        self.mini = mini#迭代停止最小误差
        cnt = len(x[0])	#样本数量
        self.theta = np.array([[0.0] for i in range(cnt)])
        self.predict = [] #存放预测值

随后就是Sigmoid函数和损失函数的实现:

	def __sigmoid(x):
        return 1/(1 + np.exp(-x))

    def __loss(self, theta):
        # 计算损失值
        sum = 0.0
        for i in range(len(self.y)):
            if y[i][0] == 1:
                sum += - \
                    float(log(LogisticModel.__sigmoid(np.dot(x[i], theta))))
            else:
                sum += - \
                    float(log(1-LogisticModel.__sigmoid(np.dot(x[i], theta))))

        return sum/len(self.y)

之后是编写梯度计算与循环检查函数:

    def __gradient(self, theta):
        # 求取梯度
        sum = 0
        for i in range(len(self.y)):
            sum += (LogisticModel.__sigmoid(
                float(np.dot(x[i], theta))) - y[i][0]) * x[i]
        sum /= len(self.y)
        ans = self.alpha*sum.reshape(-1, 1)
       	return ans
       	
    def __check(self):
        # 检查是否达到迭代边界条件
        TempOld = LogisticModel.__loss(self, self.theta)
        Theta = LogisticModel.__gradient(self, self.theta)
        self.theta -= Theta  # 更新theta
        TempNew = LogisticModel.__loss(self, self.theta)
        result = abs((abs(TempNew)-abs(TempOld)))
        if result <= self.mini:
            return False
        return True

    def fit(self):
        # 迭代梯度下降的过程
        while(LogisticModel.__check(self)):
            pass

最后的步骤就是对模型的预测与结果的输出,这里输出采用的是混淆矩阵(Confusion Matrix)

    def predictSelf(self):
        # 模型预测
        for i in range(len(self.y)):
            if(LogisticModel.__sigmoid(np.dot(self.x[i], self.theta)) > 0.5):
                self.predict.append(1)
            else:
                self.predict.append(0)

    def show(self, labels_name):
        cm = (confusion_matrix(self.y.reshape(1, -1)[0], self.predict))
        # 展示模型结果
        print("accuracy:{:.2%}".format((cm[0][0]+cm[1][1])/(len(self.y))))
        print("presicion:{:.2%}".format(cm[0][0]/(cm[0][0]+cm[0][1])))
        print("recall:{:.2%}".format(cm[0][0]/(cm[0][0]+cm[1][0])))

        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]    # 归一化
        plt.imshow(cm, interpolation='nearest')    # 在特定的窗口上显示图像
        plt.title('WaterMelon')    # 图像标题
        plt.colorbar()
        num_local = np.array(range(len(labels_name)))
        plt.xticks(num_local, labels_name, rotation=90)    # 将标签印在x轴坐标上
        plt.yticks(num_local, labels_name)    # 将标签印在y轴坐标上
        plt.ylabel('True label')
        plt.xlabel('Predicted label')
        plt.show()

在这里插入图片描述

accuracy:82.35%
presicion:77.78%
recall:87.50%   

全代码

这里额外解释一下,主函数中的x我是将Sugar_rate与density 合并在一起,y中记录的是真实值的数据。而C起初我是打算用作线性的函数常数项,但是随后发现引入C的准确率并不是很高,各位可以自己下去自行添加尝试。

import numpy as np
from numpy import log
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
np.set_printoptions(suppress=True)  # 取消科学计数法输出


class LogisticModel:
    def __init__(self, X, Y, alpha=1, mini=0.0001) -> None:
        self.x = X
        self.y = Y
        self.alpha = alpha
        self.mini = mini
        cnt = len(x[0])
        self.theta = np.array([[0.0] for i in range(cnt)])
        self.predict = []

    def __sigmoid(x):
        return 1/(1 + np.exp(-x))

    def __loss(self, theta):
        # 计算损失值
        sum = 0.0
        for i in range(len(self.y)):
            if y[i][0] == 1:
                sum += - \
                    float(log(LogisticModel.__sigmoid(np.dot(x[i], theta))))
            else:
                sum += - \
                    float(log(1-LogisticModel.__sigmoid(np.dot(x[i], theta))))

        return sum/len(self.y)

    def __gradient(self, theta):
        # 求取梯度
        sum = 0
        for i in range(len(self.y)):
            sum += (LogisticModel.__sigmoid(
                float(np.dot(x[i], theta))) - y[i][0]) * x[i]
        sum /= len(self.y)
        ans = self.alpha*sum.reshape(-1, 1)
        # print(theta - ans)
        return ans

    def __check(self):
        # 检查是否达到迭代边界条件
        TempOld = LogisticModel.__loss(self, self.theta)
        Theta = LogisticModel.__gradient(self, self.theta)
        self.theta -= Theta  # 更新theta
        TempNew = LogisticModel.__loss(self, self.theta)
        result = abs((abs(TempNew)-abs(TempOld)))
        if result <= self.mini:
            return False
        return True

    def fit(self):
        # 迭代梯度下降的过程
        while(LogisticModel.__check(self)):
            pass

    def predictSelf(self):
        # 模型预测
        for i in range(len(self.y)):
            if(LogisticModel.__sigmoid(np.dot(self.x[i], self.theta)) > 0.5):
                self.predict.append(1)
            else:
                self.predict.append(0)

    def show(self, labels_name):
        cm = (confusion_matrix(self.y.reshape(1, -1)[0], self.predict))
        # 展示模型结果
        print("accuracy:{:.2%}".format((cm[0][0]+cm[1][1])/(len(self.y))))
        print("presicion:{:.2%}".format(cm[0][0]/(cm[0][0]+cm[0][1])))
        print("recall:{:.2%}".format(cm[0][0]/(cm[0][0]+cm[1][0])))

        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]    # 归一化
        plt.imshow(cm, interpolation='nearest')    # 在特定的窗口上显示图像
        plt.title('WaterMelon')    # 图像标题
        plt.colorbar()
        num_local = np.array(range(len(labels_name)))
        plt.xticks(num_local, labels_name, rotation=90)    # 将标签印在x轴坐标上
        plt.yticks(num_local, labels_name)    # 将标签印在y轴坐标上
        plt.ylabel('True label')
        plt.xlabel('Predicted label')
        plt.show()


density = np.array([0.697, 0.774, 0.634, 0.608, 0.556, 0.403, 0.481, 0.437, 0.666,
                    0.243, 0.245, 0.343, 0.639, 0.657, 0.360, 0.593, 0.719]).reshape(-1, 1)

sugar_rate = np.array([0.460, 0.376, 0.264, 0.318, 0.215, 0.237, 0.149, 0.211, 0.091,
                       0.267, 0.057, 0.099, 0.161, 0.198, 0.370, 0.042, 0.103]).reshape(-1, 1)
# 用于迭代Theta的常数项
C = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
              1, 1, 1, 1, 1, 1]).reshape(-1, 1)
#x = np.hstack((density, sugar_rate),C)
x = np.hstack((density, sugar_rate))
y = np.array([1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
              0, 0, 0, 0, 0, 0]).reshape(-1, 1)
Test = LogisticModel(x, y)
Test.fit()
Test.predictSelf()
labels_name = ["good", "bad"]
Test.show(labels_name)




鸢尾花(Iris)数据集

鸢尾花数据集是一个多分类的数据集,获取方法可以看这篇文章
对于多分类的样本,显然不能直接使用Logistic模型对齐分类,这里介绍一种可以将二分类模型用于进行多分类的方法——投票法(VotingClassifier),以鸢尾花数据集为例,总共提供了3种不同类型的花,那么我们可以将之两两组合,形成3个分类器,预测时三个分类器分别预测其种类对其投票,票数多的即为预测结果,如果票数一致则可以任选一个种类记录

A
B
A
AB
A
BC
CA

LogisticModel

我的思路是首先对于之前的模型进行改造,使之可以适应鸢尾花的分类,
主要改变的其实就是画图的部分,去除了计算召回率和精确率(因为要分别对3个分类器求,过于繁杂),其次就是把title和混淆矩阵转移到函数外计算,

    def show(cm, labels_name, title):
        print("accuracy:{:.2%}".format(
            (cm[0][0]+cm[1][1]+cm[2][2])/(np.sum(cm))))
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]    # 归一化
        plt.imshow(cm, interpolation='nearest')    # 在特定的窗口上显示图像
        plt.title(title)    # 图像标题
        plt.colorbar()
        num_local = np.array(range(len(labels_name)))
        plt.xticks(num_local, labels_name, rotation=90)    # 将标签印在x轴坐标上
        plt.yticks(num_local, labels_name)    # 将标签印在y轴坐标上
        plt.ylabel('True label')
        plt.xlabel('Predicted label')
        plt.show()

还有就是对于梯度下降的界定条件由0.0001降低了一个百分比到0.001,原因是之后在我计算时,发现对于其中的一个模型来说,原先的精度会需要迭代更多的次数,有可能是深陷局部最小值难以跳出,加之降低精度后最终预测结果也可以接受,故改之。其实也可以改良梯度下降算法,例如:动量梯度下降法(gradient descent with momentum) 大家可以自行尝试

class LogisticModel:
    def __init__(self, X, Y, alpha=1, mini=0.001) -> None:
        self.x = X
        self.y = Y
        self.alpha = alpha
        self.mini = mini
        cnt = len(self.x[0])
        self.theta = np.array([[0.0] for i in range(cnt)])
        self.predict = []

全代码

import numpy as np
from numpy import log
import matplotlib.pyplot as plt
np.set_printoptions(suppress=True)  # 取消科学计数法输出


class LogisticModel:
    def __init__(self, X, Y, alpha=1, mini=0.001) -> None:
        self.x = X
        self.y = Y
        self.alpha = alpha
        self.mini = mini
        cnt = len(self.x[0])
        self.theta = np.array([[0.0] for i in range(cnt)])
        self.predict = []

    def sigmoid(x):
        return 1/(1 + np.exp(-x))

    def __loss(self, theta):
        # 计算损失值
        sum = 0.0
        for i in range(len(self.y)):
            if self.y[i][0] == 1:
                sum += - \
                    float(log(LogisticModel.sigmoid(
                        np.dot(self.x[i], theta))))
            else:
                sum += - \
                    float(
                        log(1-LogisticModel.sigmoid(np.dot(self.x[i], theta))))

        return sum/len(self.y)

    def __gradient(self, theta):
        # 求取梯度
        sum = 0
        for i in range(len(self.y)):
            sum += (LogisticModel.sigmoid(
                float(np.dot(self.x[i], theta))) - self.y[i][0]) * self.x[i]
        sum /= len(self.y)
        ans = self.alpha*sum.reshape(-1, 1)
        # print(theta - ans)
        return ans

    def __check(self):
        # 检查是否达到迭代边界条件
        TempOld = LogisticModel.__loss(self, self.theta)
        Theta = LogisticModel.__gradient(self, self.theta)
        self.theta -= Theta  # 更新theta
        TempNew = LogisticModel.__loss(self, self.theta)
        result = abs((abs(TempNew)-abs(TempOld)))
        if result <= self.mini:
            return False
        return True

    def fit(self):
        # 迭代梯度下降的过程
        while(LogisticModel.__check(self)):
            pass

    def predictSelf(self):
        # 模型预测
        for i in range(len(self.y)):
            if(LogisticModel.sigmoid(np.dot(self.x[i], self.theta)) > 0.5):
                self.predict.append(1)
            else:
                self.predict.append(0)

    # def show_theta(self):
    #     print(self.theta)

    def show(cm, labels_name, title):
        print("accuracy:{:.2%}".format(
            (cm[0][0]+cm[1][1]+cm[2][2])/(np.sum(cm))))
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]    # 归一化
        plt.imshow(cm, interpolation='nearest')    # 在特定的窗口上显示图像
        plt.title(title)    # 图像标题
        plt.colorbar()
        num_local = np.array(range(len(labels_name)))
        plt.xticks(num_local, labels_name, rotation=90)    # 将标签印在x轴坐标上
        plt.yticks(num_local, labels_name)    # 将标签印在y轴坐标上
        plt.ylabel('True label')
        plt.xlabel('Predicted label')
        plt.show()

主函数实现

首先就是数据的读取和分类器的构建,这里我提供的标签训练值统一为前50位为1,后50位为0的列表,这是为了能够直接复用ModelLogistic类,回忆西瓜数据集时,我们正例标记为1,负例标记为0。这里相当于组合的前50类别标记为正,后50标记为负,因为鸢尾花的数据集十分规整,所以我们可以很轻易地将其分出3个类别。

Labels_name = ['SepalLength', 'SepalWidth',
               'PetalLength', 'PetalWidth', 'Species']
# 读取表格数据
iris = pd.read_csv("D:\Code\python\Iris.csv", header=0, names=Labels_name)
x = np.hstack((np.array(iris[u'SepalLength']).reshape(-1, 1), 
               np.array(iris[u'SepalWidth']).reshape(-1, 1),
               np.array(iris[u'PetalLength']).reshape(-1, 1),
               np.array(iris[u'PetalWidth']).reshape(-1, 1)))

Y = np.hstack([[1]*50, [0]*50]).reshape(-1, 1)
x_SVer = np.vstack([x[0:50], x[50:100]])
x_VerVir = np.vstack([x[50:100], x[100:150]])
x_VirS = np.vstack([x[100:150], x[0:50]])

ModelA = LogisticModel(x_SVer, Y)
ModelB = LogisticModel(x_VerVir, Y)
ModelC = LogisticModel(x_VirS, Y)

ModelA.fit()
ModelB.fit()
ModelC.fit()

随后是编写投票器预测模型,免不了大量if语句:

def predict(a, b, c, test, pre):
    for i in range(len(test)):
        # 记票器
        list = [0, 0, 0]
        if(LogisticModel.sigmoid(np.dot(test[i], a.theta))) > 0.5:
            list[0] += 1
        else:
            list[1] += 1
        if(LogisticModel.sigmoid(np.dot(test[i], b.theta))) > 0.5:
            list[1] += 1
        else:
            list[2] += 1
        if(LogisticModel.sigmoid(np.dot(test[i], c.theta))) > 0.5:
            list[2] += 1
        else:
            list[0] += 1
        if(list[0] ^ list[1] ^ list[2] == 1):
            pre.append("Iris-versicolor")
        else:
            if(list.index(2) == 0):
                pre.append("Iris-setosa")
            elif(list.index(2) == 1):
                pre.append("Iris-versicolor")
            elif(list.index(2) == 2):
                pre.append("Iris-virginica")

这里的测试集需要我们自己划分,调用sklearn中的 train_test_split函数进行划分:

from sklearn.model_selection import train_test_split
y = np.array(iris[u'Species']).reshape(-1, 1)  # 标签
x_train, x_test, y_train, y_test = train_test_split(
    x, y, test_size=0.6)  # 划分数据集

最后一步,预测+输出最终结果:

pre = []  # 存储预测结果
predict(ModelA, ModelB, ModelC, x_test, pre)
cm = (confusion_matrix(y_test, np.array(pre).reshape(-1, 1)))
print(cm)
title = "Iris Prediction"
LogisticModel.show(cm, ['setosa', 'versicolor', 'virginica'], title)

全代码

from LogisticModel import LogisticModel
import pandas as pd
import numpy as np
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
np.set_printoptions(suppress=True)  # 取消科学计数法输出


def predict(a, b, c, test, pre):
    for i in range(len(test)):
        # 记票器
        list = [0, 0, 0]
        if(LogisticModel.sigmoid(np.dot(test[i], a.theta))) > 0.5:
            list[0] += 1
        else:
            list[1] += 1
        if(LogisticModel.sigmoid(np.dot(test[i], b.theta))) > 0.5:
            list[1] += 1
        else:
            list[2] += 1
        if(LogisticModel.sigmoid(np.dot(test[i], c.theta))) > 0.5:
            list[2] += 1
        else:
            list[0] += 1
        if(list[0] ^ list[1] ^ list[2] == 1):
            pre.append("Iris-versicolor")
        else:
            if(list.index(2) == 0):
                pre.append("Iris-setosa")
            elif(list.index(2) == 1):
                pre.append("Iris-versicolor")
            elif(list.index(2) == 2):
                pre.append("Iris-virginica")


Labels_name = ['SepalLength', 'SepalWidth',
               'PetalLength', 'PetalWidth', 'Species']
# 读取表格数据
iris = pd.read_csv("D:\Code\python\Iris.csv", header=0, names=Labels_name)
x = np.hstack((np.array(iris[u'SepalLength']).reshape(-1, 1),
               np.array(iris[u'SepalWidth']).reshape(-1, 1),
               np.array(iris[u'PetalLength']).reshape(-1, 1),
               np.array(iris[u'PetalWidth']).reshape(-1, 1)))

Y = np.hstack([[1]*50, [0]*50]).reshape(-1, 1)
x_SVer = np.vstack([x[0:50], x[50:100]])
x_VerVir = np.vstack([x[50:100], x[100:150]])
x_VirS = np.vstack([x[100:150], x[0:50]])

ModelA = LogisticModel(x_SVer, Y)
ModelB = LogisticModel(x_VerVir, Y)
ModelC = LogisticModel(x_VirS, Y)

ModelA.fit()
ModelB.fit()
ModelC.fit()


y = np.array(iris[u'Species']).reshape(-1, 1)  # 标签
x_train, x_test, y_train, y_test = train_test_split(
    x, y, test_size=0.6)  # 划分数据集

pre = []  # 存储预测结果
predict(ModelA, ModelB, ModelC, x_test, pre)
cm = (confusion_matrix(y_test, np.array(pre).reshape(-1, 1)))
print(cm)
title = "Iris Prediction"
LogisticModel.show(cm, ['setosa', 'versicolor', 'virginica'], title)

在这里插入图片描述
在这里插入图片描述
最终的结果应该是会在95%~99%之间波动

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python实现Logistc回归分类(西瓜数据集、鸢尾花数据集)详解 的相关文章

  • RedHat 6.5(x86_64)启动nagios客户端nrpe报错的解决方法

    tar xvf nagios tar gz C usr local usr local nagios bin nrpe c usr local nagios etc nrpe cfg d bash usr local nagios bin
  • wifi dhcp linux,archlinux 安装前的网络设置 静态IP DHCP 无线WIFI

    安装版本archlinux 20200701 xff0c 在安装前的网络配置 一 准备阶段 xff0c 查看网卡状态是否up xff0c 设置网卡为up状态 查看网卡信息 ip link 如果要使用的网卡包含state down字段 xff
  • java 判断 string null_java 字符串为null 如何判断

    判别一个字符串str不为空的办法有 xff1a 1 str 61 61 null 2 str isEmpty str 61 61 null 是有必要存在的 假如 String 类型为null 而去停止 equals String 或 len
  • What is my IP?

    今天介绍2个小工具 放心 xff0c 都是绿色的 xff0c 而且免安装 第一个叫whatismyip com 正如其名 xff0c 这个工具是用来看自己的IP的 啥 xff1f 你觉得太胡扯 xff1f 你是不是觉得看自己IP地址太简单
  • libqxt编译

    一 说明 编译环境 xff1a win10 qt5 6 1 1 vs2013和libqxt源码 从git上下载 libqxt xff1a libqxt 关于libqxt的说明 xff0c 请到libqxt的官网阅读 xff0c 说着看图1
  • ASP.NET CORE系列【五】webapi整理以及RESTful风格化

    原文 ASP NET CORE系列 五 webapi整理以及RESTful风格化 介绍 什么是RESTful xff1f 这里不多做赘述 xff0c 详情请百度 xff01 哈哈 xff0c 本来还想巴拉巴拉介绍一些webapi RESTf
  • mac系统如何生成SSH key与GitHub通信

    一 检查 SSH key 是否存在 在终端输入 xff1a ls al ssh 如果没有 xff0c 终端显示如下 xff1a No such file or directory 如果已经存在 xff0c 则会显示 id rsa 和 id
  • TortoiseSVN 忽略文件 忽略已提交文件

    主要以下两种情况 xff1a 1 首次提交就做好了忽略拦截 xff1a 项目首次提交到svn服务器的时候 xff0c 把该删的删了 xff0c 然后设置忽略规则 xff0c 就没问题了 2 提交一段时间忽然想忽略拦截 xff1a 经常碰到的
  • java里getter和setter的作用和区别是什么?

    java是典型的面向对象的编程语言 xff0c 面向对象三个特性 xff0c 继承性 xff0c 多态性 xff0c 封装性 xff0c 主要和封装性考虑 xff0c 类里面的变量不想设置成公共的类型 xff0c 但是还要给外部使用在这种实
  • FC金手指使用方法+大全

    一 文章来由 童年 小时候除了小霸王FC主机 xff0c 然后就是世嘉MD主机 xff0c 玩的好多啊 xff0c 但有些游戏一直没打穿留下遗憾 网上找金手指使用方法 xff0c 都真真假假 xff0c 鱼龙混杂 xff0c 试了很多终于得
  • shell根据关键字获取文件某一行的行号

    为什么80 的码农都做不了架构师 xff1f gt gt gt cat n 文件名 grep 39 关键字 39 awk 39 print 1 39 cat n是获取行号 xff0c 要是获取行内容 xff0c 去掉 n就可以了 转载于 h
  • VS Code编译支持C++11问题

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 如果你正确配置了 xff0c 能正确编译c 43 43 xff0c 但是发现auto等一些关键词不能使用 xff0c 那么 xff0c 请尝试如下操作 xff1a 打开ta
  • word2007自动生成参考文献引用并且右上角标注

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 在写毕业论文时 xff0c 总要处理四五十篇的参考文献的引用 xff0c 本文就介绍如何快捷自动生成参考文献引用 xff0c 同时实现参考文献右上角标注 打开需要排版的论文
  • matlab练习程序(随机粒子切换特效)

    视频制作软件中一般都会有相邻帧切换的特效 xff0c 我过去用过vagas好像就有很多切换特效 我想这个也算是其中一种吧 xff0c 虽然我不确定实际中到底有没有这种切换 实际上我只是下班后太无聊了 xff0c 写着玩的 xff0c 没什么
  • PyQt4(简单信号槽)

    import sys from PyQt4 import QtCore QtGui class myWidget QtGui QWidget def init self super myWidget self init self setWi
  • 模拟京东商城登陆HttpRequest

    利用Winform HttpRequest 模拟登陆京东商城 目前只获取订单信息 xff0c 可以获取图片等其他信息 1 using System 2 using System Collections Generic 3 using Sys
  • Nginx (一)Windows下编译Nginx源码以及安装 nginx for windows方法步骤

    转载自 http apps hi baidu com share detail 11192699 content Nginx介绍 xff1a Nginx 34 engine x 34 是一个高性能的 HTTP 和反向代理服务器 xff0c
  • 我所理解的人工智能

    很多人容易把人工智能理解为机器人 机器人是人工智能的一个实际体现 人工智能应用很广泛 下面我来谈谈我的理解 人工智能可分开理解为 人工 和 智能 xff0c 即人类创造出来的智能 xff0c 从广义上来讲只要人类创造出来 xff0c 能为人
  • [Oracle数据库] 存储过程出错 :PLS-00103: 出现符号 "("在需要下列之一时: := . ) , @...

    讨论原因之一 xff1a 我写的简单存储过程如下 xff1a create or replace procedure p c v date in varchar2 200 is t count number begin select cou
  • Android读写properties配置文件

    写这篇文章之前可以成功运行 文章后就各种找不到文件 所以并没有采用此种方式 后期完善 详见下篇解决方案 配置文件读取很容易 修改需要注意权限 比如assets目录下就不允许修改 配置文件的创建 New File 命名后选择propertie

随机推荐

  • el-select数据过多懒加载(loadmore)

    el select数据过多处理方式 在日常项目中el select组件的使用频率是非常之高的 当数据过多时渲染时间非常长 这里提供几个处理方式 远程搜索 组件提供了远程搜索方式 也就是按照你输入的结果匹配选项 官网提供了参考示例 这里不加赘
  • Node连接Mysql遇到的坑以及踩坑总结

    前段时间做的项目中 xff0c 要用到 express 43 mysql 先看看我最初的实现代码 xff1a var conn 61 mysql createConnection host 39 example org 39 user 39
  • Cisco交换机配置新手篇之端口配置

    上回跟大家介绍了 如何正确连接交换机 xff0c 今天用一些配置片段给大家介绍一下端口的配置 鉴于网上大多数配置事例都是show run出来的结果 不利于新手对命令配置过程的了解 xff0c 所以笔者将配置片段和注意的地方都注明了一下 xf
  • 批处理:FOR的参数/F之delims详解

    xff08 三 xff09 delims 61 符号集 分隔符 格式 xff1a FOR F 34 Delims 61 符号集 34 I IN Command1 DO Command2 用法 xff1a 一句话总结 xff1a 忽略分隔符
  • springboot 单元测试 指定启动类

    问题 在做单元测试时 xff0c 写了一个工具类 xff0c 用于注入spring的上下文 public class AppBeanUtil implements ApplicationContextAware private static
  • 多项式系数提取算法 c++

    bool isNumber char s if s gt 61 48 amp amp s lt 61 57 return true else return false bool isLetter char s if s gt 61 97 a
  • matlab练习程序(透视变换)

    close all clc H 61 1 索引pix中第一个元素 xff0c 即高度 W 61 2 索引pix中第二个元素 xff0c 即宽度 left right 61 0 3 抬起左边或右边时值为0 1 之间 xff0c 不抬起时为0
  • 【Java】SHA加密

    package sdfg import java math BigInteger import java security MessageDigest import java security NoSuchAlgorithmExceptio
  • 改变虚拟导航栏(navigation bar)背景色及图标颜色

    众所周知 xff0c 安卓系统中存在着虚拟导航栏 xff0c 它们不是实体按键 xff0c 而是通过软件实现的 一般而言 xff0c 虚拟导航栏是长成下面这样的 xff1a 系统中默认的虚拟导航栏的背景色是黑色 xff0c 按键的颜色是白色
  • java 去掉 if else_Java 通过注解消除if else

    半夜睡醒出门吃宵夜回家锁坏了 被逼无奈去了网吧正好想起之前构思的消除ifelse的方案正好就试了试 经过几小时奋斗修修改改终于实现了效果 特此分享 具体的流程如上 大概的场景是 在 web项目中有很多方法是要携带token或其他的操作才可以
  • linux上传文件的命令

    由于svm挂机不能通过svn提交代码 xff0c 所以今天尝试了一下linux的rz和sz命令 1 sz命令是把文件下载到本地 xff0c 使用方法如下 sz 文件名 回车之后会弹出一个本地的路径选择框 xff0c 选择要下载的路径即可 2
  • Python自动化备份系统及网站

    随着目前IT迅猛的发展 xff0c 自动化运维对于Linux运维人员也越来越重要 xff0c 传统的运维方式靠大量的人力 xff0c 现在也逐渐转向自动化运维 xff0c 我们常见的跟自动化有关的软件有哪些呢 今天我们来简单列举一下 xff
  • iOS中 项目开发易错知识点总结 韩俊强的博客

    每日更新关注 http weibo com hanjunqiang 新浪微博 xff01 点击return取消textView 的响应者 BOOL textFieldShouldReturn UITextField textField co
  • VNC常用操作及常见问题解决办法汇总

    VNC登录用户缺省是root xff0c 但在安装oracle时必须用oracle用户的身份登录 xff0c 下面我们就以oracle为例说明如何配置VNC xff0c 从而可以使用不同的用户登录到主机 步骤描述如下 xff1a 步骤一 x
  • Debian隐藏桌面图标

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 运行gconf editor xff0c 找到apps nautilus desktop 然后将所要隐藏的图表的visible勾掉就可以了 转载于 https my osc
  • 第四次作业:Windows各种基本应用的命令处理方法

    删除文件夹命令 xff1f rd remove directory 如何给文件夹重新命名 xff1f ren rename 如何在文件夹中建立文件夹 xff1f md swift a 如何用命令查看文本文件的内容 xff1f type sw
  • Nginx访问ftp目录时权限问题

    在将nginx目录设置为ftp目录访问时会报错 xff1a 403 forbidden 这是权限问题 xff0c 解决方法是在配置文件中增加User vi usr local nginx conf nginx conf 增加user可以是r
  • SpringBoot-@PathVariable

    URL变量 在上一个博客中 xff0c 学习了如何在 64 Controller中创建 64 RequestMapping xff08 或者响应的简写 xff09 来处理不同的URL请求 但是在Web应用中URL通常不是一成不变的 xff0
  • maven - dependencies与dependencyManagement的区别

    1 DepencyManagement应用场景 当我们的项目模块很多的时候 xff0c 我们使用Maven管理项目非常方便 xff0c 帮助我们管理构建 文档 报告 依赖 scms 发布 分发的方法 可以方便的编译代码 进行依赖管理 管理二
  • Python实现Logistc回归分类(西瓜数据集、鸢尾花数据集)详解

    文章目录 Logistic回归原理讲解逻辑回归的损失函数梯度下降 代码实现西瓜数据集全代码 鸢尾花 xff08 Iris xff09 数据集LogisticModel全代码 主函数实现全代码 Logistic回归原理讲解 声明 笔者实验之前