A. 用python實現紅酒數據集的ID3,C4.5和CART演算法
ID3演算法介紹
ID3演算法全稱為迭代二叉樹3代演算法(Iterative Dichotomiser 3)
該演算法要先進行特徵選擇,再生成決策樹,其中特徵選擇是基於「信息增益」最大的原則進行的。
但由於決策樹完全基於訓練集生成的,有可能對訓練集過於「依賴」,即產生過擬合現象。因此在生成決策樹後,需要對決策樹進行剪枝。剪枝有兩種形式,分別為前剪枝(Pre-Pruning)和後剪枝(Post-Pruning),一般採用後剪枝。
信息熵、條件熵和信息增益
信息熵:來自於香農定理,表示信息集合所含信息的平均不確定性。信息熵越大,表示不確定性越大,所含的信息量也就越大。
設x 1 , x 2 , x 3 , . . . x n {x_1, x_2, x_3, ...x_n}x
1
,x
2
,x
3
,...x
n
為信息集合X的n個取值,則x i x_ix
i
的概率:
P ( X = i ) = p i , i = 1 , 2 , 3 , . . . , n P(X=i) = p_i, i=1,2,3,...,n
P(X=i)=p
i
,i=1,2,3,...,n
信息集合X的信息熵為:
H ( X ) = − ∑ i = 1 n p i log p i H(X) =- \sum_{i=1}^{n}{p_i}\log{p_i}
H(X)=−
i=1
∑
n
p
i
logp
i
條件熵:指已知某個隨機變數的情況下,信息集合的信息熵。
設信息集合X中有y 1 , y 2 , y 3 , . . . y m {y_1, y_2, y_3, ...y_m}y
1
,y
2
,y
3
,...y
m
組成的隨機變數集合Y,則隨機變數(X,Y)的聯合概率分布為
P ( x = i , y = j ) = p i j P(x=i,y=j) = p_{ij}
P(x=i,y=j)=p
ij
條件熵:
H ( X ∣ Y ) = ∑ j = 1 m p ( y j ) H ( X ∣ y j ) H(X|Y) = \sum_{j=1}^m{p(y_j)H(X|y_j)}
H(X∣Y)=
j=1
∑
m
p(y
j
)H(X∣y
j
)
由
H ( X ∣ y j ) = − ∑ j = 1 m p ( y j ) ∑ i = 1 n p ( x i ∣ y j ) log p ( x i ∣ y j ) H(X|y_j) = - \sum_{j=1}^m{p(y_j)}\sum_{i=1}^n{p(x_i|y_j)}\log{p(x_i|y_j)}
H(X∣y
j
)=−
j=1
∑
m
p(y
j
)
i=1
∑
n
p(x
i
∣y
j
)logp(x
i
∣y
j
)
和貝葉斯公式:
p ( x i y j ) = p ( x i ∣ y j ) p ( y j ) p(x_iy_j) = p(x_i|y_j)p(y_j)
p(x
i
y
j
)=p(x
i
∣y
j
)p(y
j
)
可以化簡條件熵的計算公式為:
H ( X ∣ Y ) = ∑ j = 1 m ∑ i = 1 n p ( x i , y j ) log p ( x i ) p ( x i , y j ) H(X|Y) = \sum_{j=1}^m \sum_{i=1}^n{p(x_i, y_j)\log\frac{p(x_i)}{p(x_i, y_j)}}
H(X∣Y)=
j=1
∑
m
i=1
∑
n
p(x
i
,y
j
)log
p(x
i
,y
j
)
p(x
i
)
信息增益:信息熵-條件熵,用於衡量在知道已知隨機變數後,信息不確定性減小越大。
d ( X , Y ) = H ( X ) − H ( X ∣ Y ) d(X,Y) = H(X) - H(X|Y)
d(X,Y)=H(X)−H(X∣Y)
python代碼實現
import numpy as np
import math
def calShannonEnt(dataSet):
""" 計算信息熵 """
labelCountDict = {}
for d in dataSet:
label = d[-1]
if label not in labelCountDict.keys():
labelCountDict[label] = 1
else:
labelCountDict[label] += 1
entropy = 0.0
for l, c in labelCountDict.items():
p = 1.0 * c / len(dataSet)
entropy -= p * math.log(p, 2)
return entropy
def filterSubDataSet(dataSet, colIndex, value):
"""返回colIndex特徵列label等於value,並且過濾掉改特徵列的數據集"""
subDataSetList = []
for r in dataSet:
if r[colIndex] == value:
newR = r[:colIndex]
newR = np.append(newR, (r[colIndex + 1:]))
subDataSetList.append(newR)
return np.array(subDataSetList)
def chooseFeature(dataSet):
""" 通過計算信息增益選擇最合適的特徵"""
featureNum = dataSet.shape[1] - 1
entropy = calShannonEnt(dataSet)
bestInfoGain = 0.0
bestFeatureIndex = -1
for i in range(featureNum):
uniqueValues = np.unique(dataSet[:, i])
condition_entropy = 0.0
for v in uniqueValues: #計算條件熵
subDataSet = filterSubDataSet(dataSet, i, v)
p = 1.0 * len(subDataSet) / len(dataSet)
condition_entropy += p * calShannonEnt(subDataSet)
infoGain = entropy - condition_entropy #計算信息增益
if infoGain >= bestInfoGain: #選擇最大信息增益
bestInfoGain = infoGain
bestFeatureIndex = i
return bestFeatureIndex
def creatDecisionTree(dataSet, featNames):
""" 通過訓練集生成決策樹 """
featureName = featNames[:] # 拷貝featNames,此處不能直接用賦值操作,否則新變數會指向舊變數的地址
classList = list(dataSet[:, -1])
if len(set(classList)) == 1: # 只有一個類別
return classList[0]
if dataSet.shape[1] == 1: #當所有特徵屬性都利用完仍然無法判斷樣本屬於哪一類,此時歸為該數據集中數量最多的那一類
return max(set(classList), key=classList.count)
bestFeatureIndex = chooseFeature(dataSet) #選擇特徵
bestFeatureName = featNames[bestFeatureIndex]
del featureName[bestFeatureIndex] #移除已選特徵列
decisionTree = {bestFeatureName: {}}
featureValueUnique = sorted(set(dataSet[:, bestFeatureIndex])) #已選特徵列所包含的類別, 通過遞歸生成決策樹
for v in featureValueUnique:
FeatureName = featureName[:]
subDataSet = filterSubDataSet(dataSet, bestFeatureIndex, v)
decisionTree[bestFeatureName][v] = creatDecisionTree(subDataSet, FeatureName)
return decisionTree
def classify(decisionTree, featnames, featList):
""" 使用訓練所得的決策樹進行分類 """
classLabel = None
root = decisionTree.keys()[0]
firstGenDict = decisionTree[root]
featIndex = featnames.index(root)
for k in firstGenDict.keys():
if featList[featIndex] == k:
if isinstance(firstGenDict[k], dict): #若子節點仍是樹,則遞歸查找
classLabel = classify(firstGenDict[k], featnames, featList)
else:
classLabel = firstGenDict[k]
return classLabel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
下面用鳶尾花數據集對該演算法進行測試。由於ID3演算法只能用於標稱型數據,因此用在對連續型的數值數據上時,還需要對數據進行離散化,離散化的方法稍後說明,此處為了簡化,先使用每一種特徵所有連續性數值的中值作為分界點,小於中值的標記為1,大於中值的標記為0。訓練1000次,統計准確率均值。
from sklearn import datasets
from sklearn.model_selection import train_test_split
iris = datasets.load_iris()
data = np.c_[iris.data, iris.target]
scoreL = []
for i in range(1000): #對該過程進行10000次
trainData, testData = train_test_split(data) #區分測試集和訓練集
featNames = iris.feature_names[:]
for i in range(trainData.shape[1] - 1): #對訓練集每個特徵,以中值為分界點進行離散化
splitPoint = np.mean(trainData[:, i])
featNames[i] = featNames[i]+'<='+'{:.3f}'.format(splitPoint)
trainData[:, i] = [1 if x <= splitPoint else 0 for x in trainData[:, i]]
testData[:, i] = [1 if x <= splitPoint else 0 for x in testData[:, i]]
decisionTree = creatDecisionTree(trainData, featNames)
classifyLable = [classify(decisionTree, featNames, td) for td in testData]
scoreL.append(1.0 * sum(classifyLable == testData[:, -1]) / len(classifyLable))
print 'score: ', np.mean(scoreL)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
輸出結果為:score: 0.7335,即准確率有73%。每次訓練和預測的准確率分布如下:
數據離散化
然而,在上例中對特徵值離散化的劃分點實際上過於「野蠻」,此處介紹一種通過信息增益最大的標准來對數據進行離散化。原理很簡單,當信息增益最大時,說明用該點劃分能最大程度降低數據集的不確定性。
具體步驟如下:
對每個特徵所包含的數值型特徵值排序
對相鄰兩個特徵值取均值,這些均值就是待選的劃分點
用每一個待選點把該特徵的特徵值劃分成兩類,小於該特徵點置為1, 大於該特徵點置為0,計算此時的條件熵,並計算出信息增益
選擇信息使信息增益最大的劃分點進行特徵離散化
實現代碼如下:
def filterRawData(dataSet, colIndex, value, tag):
""" 用於把每個特徵的連續值按照區分點分成兩類,加入tag參數,可用於標記篩選的是哪一部分數據"""
filterDataList = []
for r in dataSet:
if (tag and r[colIndex] <= value) or ((not tag) and r[colIndex] > value):
newR = r[:colIndex]
newR = np.append(newR, (r[colIndex + 1:]))
filterDataList.append(newR)
return np.array(filterDataList)
def dataDiscretization(dataSet, featName):
""" 對數據每個特徵的數值型特徵值進行離散化 """
featureNum = dataSet.shape[1] - 1
entropy = calShannonEnt(dataSet)
for featIndex in range(featureNum): #對於每一個特徵
uniqueValues = sorted(np.unique(dataSet[:, featIndex]))
meanPoint = []
for i in range(len(uniqueValues) - 1): # 求出相鄰兩個值的平均值
meanPoint.append(float(uniqueValues[i+1] + uniqueValues[i]) / 2.0)
bestInfoGain = 0.0
bestMeanPoint = -1
for mp in meanPoint: #對於每個劃分點
subEntropy = 0.0 #計算該劃分點的信息熵
for tag in range(2): #分別劃分為兩類
subDataSet = filterRawData(dataSet, featIndex, mp, tag)
p = 1.0 * len(subDataSet) / len(dataSet)
subEntropy += p * calShannonEnt(subDataSet)
## 計算信息增益
infoGain = entropy - subEntropy
## 選擇最大信息增益
if infoGain >= bestInfoGain:
bestInfoGain = infoGain
bestMeanPoint = mp
featName[featIndex] = featName[featIndex] + "<=" + "{:.3f}".format(bestMeanPoint)
dataSet[:, featIndex] = [1 if x <= bestMeanPoint else 0 for x in dataSet[:, featIndex]]
return dataSet, featName
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
重新對數據進行離散化,並重復該步驟1000次,同時用sklearn中的DecisionTreeClassifier對相同數據進行分類,分別統計平均准確率。運行代碼如下:
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
scoreL = []
scoreL_sk = []
for i in range(1000): #對該過程進行1000次
featNames = iris.feature_names[:]
trainData, testData = train_test_split(data) #區分測試集和訓練集
trainData_tmp = .(trainData)
testData_tmp = .(testData)
discritizationData, discritizationFeatName= dataDiscretization(trainData, featNames) #根據信息增益離散化
for i in range(testData.shape[1]-1): #根據測試集的區分點離散化訓練集
splitPoint = float(discritizationFeatName[i].split('<=')[-1])
testData[:, i] = [1 if x<=splitPoint else 0 for x in testData[:, i]]
decisionTree = creatDecisionTree(trainData, featNames)
classifyLable = [classify(decisionTree, featNames, td) for td in testData]
scoreL.append(1.0 * sum(classifyLable == testData[:, -1]) / len(classifyLable))
clf = DecisionTreeClassifier('entropy')
clf.fit(trainData[:, :-1], trainData[:, -1])
clf.predict(testData[:, :-1])
scoreL_sk.append(clf.score(testData[:, :-1], testData[:, -1]))
print 'score: ', np.mean(scoreL)
print 'score-sk: ', np.mean(scoreL_sk)
fig = plt.figure(figsize=(10, 4))
plt.subplot(1,2,1)
pd.Series(scoreL).hist(grid=False, bins=10)
plt.subplot(1,2,2)
pd.Series(scoreL_sk).hist(grid=False, bins=10)
plt.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
兩者准確率分別為:
score: 0.7037894736842105
score-sk: 0.7044736842105263
准確率分布如下:
兩者的結果非常一樣。
(但是。。為什麼根據信息熵離散化得到的准確率比直接用均值離散化的准確率還要低啊??哇的哭出聲。。)
最後一次決策樹圖形如下:
決策樹剪枝
由於決策樹是完全依照訓練集生成的,有可能會有過擬合現象,因此一般會對生成的決策樹進行剪枝。常用的是通過決策樹損失函數剪枝,決策樹損失函數表示為:
C a ( T ) = ∑ t = 1 T N t H t ( T ) + α ∣ T ∣ C_a(T) = \sum_{t=1}^TN_tH_t(T) +\alpha|T|
C
a
(T)=
t=1
∑
T
N
t
H
t
(T)+α∣T∣
其中,H t ( T ) H_t(T)H
t
(T)表示葉子節點t的熵值,T表示決策樹的深度。前項∑ t = 1 T N t H t ( T ) \sum_{t=1}^TN_tH_t(T)∑
t=1
T
N
t
H
t
(T)是決策樹的經驗損失函數當隨著T的增加,該節點被不停的劃分的時候,熵值可以達到最小,然而T的增加會使後項的值增大。決策樹損失函數要做的就是在兩者之間進行平衡,使得該值最小。
對於決策樹損失函數的理解,如何理解決策樹的損失函數? - 陶輕松的回答 - 知乎這個回答寫得挺好,可以按照答主的思路理解一下
C4.5演算法
ID3演算法通過信息增益來進行特徵選擇會有一個比較明顯的缺點:即在選擇的過程中該演算法會優先選擇類別較多的屬性(這些屬性的不確定性小,條件熵小,因此信息增益會大),另外,ID3演算法無法解決當每個特徵屬性中每個分類都只有一個樣本的情況(此時每個屬性的條件熵都為0)。
C4.5演算法ID3演算法的改進,它不是依據信息增益進行特徵選擇,而是依據信息增益率,它添加了特徵分裂信息作為懲罰項。定義分裂信息:
S p l i t I n f o ( X , Y ) = − ∑ i n ∣ X i ∣ ∣ X ∣ log ∣ X i ∣ ∣ X ∣ SplitInfo(X, Y) =-\sum_i^n\frac{|X_i|}{|X|}\log\frac{|X_i|}{|X|}
SplitInfo(X,Y)=−
i
∑
n
∣X∣
∣X
i
∣
log
∣X∣
∣X
i
∣
則信息增益率為:
G a i n R a t i o ( X , Y ) = d ( X , Y ) S p l i t I n f o ( X , Y ) GainRatio(X,Y)=\frac{d(X,Y)}{SplitInfo(X, Y)}
GainRatio(X,Y)=
SplitInfo(X,Y)
d(X,Y)
關於ID3和C4.5演算法
在學習分類回歸決策樹演算法時,看了不少的資料和博客。關於這兩個演算法,ID3演算法是最早的分類演算法,這個演算法剛出生的時候其實帶有很多缺陷:
無法處理連續性特徵數據
特徵選取會傾向於分類較多的特徵
沒有解決過擬合的問題
沒有解決缺失值的問題
即該演算法出生時是沒有帶有連續特徵離散化、剪枝等步驟的。C4.5作為ID3的改進版本彌補列ID3演算法不少的缺陷:
通過信息最大增益的標准離散化連續的特徵數據
在選擇特徵是標准從「最大信息增益」改為「最大信息增益率」
通過加入正則項系數對決策樹進行剪枝
對缺失值的處理體現在兩個方面:特徵選擇和生成決策樹。初始條件下對每個樣本的權重置為1。
特徵選擇:在選取最優特徵時,計算出每個特徵的信息增益後,需要乘以一個**「非缺失值樣本權重占總樣本權重的比例」**作為系數來對比每個特徵信息增益的大小
生成決策樹:在生成決策樹時,對於缺失的樣本我們按照一定比例把它歸屬到每個特徵值中,比例為該特徵每一個特徵值占非缺失數據的比重
關於C4.5和CART回歸樹
作為ID3的改進版本,C4.5克服了許多缺陷,但是它自身還是存在不少問題:
C4.5的熵運算中涉及了對數運算,在數據量大的時候效率非常低。
C4.5的剪枝過於簡單
C4.5隻能用於分類運算不能用於回歸
當特徵有多個特徵值是C4.5生成多叉樹會使樹的深度加深
————————————————
版權聲明:本文為CSDN博主「Sarah Huang」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_44794704/article/details/89406612
B. 為什麼id3樹不能處理連續性屬性
ID3演算法是決策樹的一個經典的構造演算法,在一段時期內曾是同類研究工作的比較對象,但通過近些年國內外學者的研究,ID3演算法也暴露出一些問題,具體如下:
(1)信息增益的計算依賴於特徵數目較多的特徵,而屬性取值最多的屬性並不一定最優。
(2)ID3是非遞增演算法。
(3)ID3是單變數決策樹(在分枝節點上只考慮單個屬性),許多復雜概念的表達困難,屬性相互關系強調不夠,容易導致決策樹中子樹的重復或有些屬性在決策樹的某一路徑上被檢驗多次。
(4)抗噪性差,訓練例子中正例和反例的比例較難控制。
於是Quilan改進了ID3,提出了C4.5演算法。C4.5演算法現在已經成為最經典的決策樹構造演算法,排名數據挖掘十大經典演算法之首,下一篇文章將重點討論。
決策樹的經典構造演算法——C4.5(WEKA中稱J48)
由於ID3演算法在實際應用中存在一些問題,於是Quilan提出了C4.5演算法,嚴格上說C4.5隻能是ID3的一個改進演算法。
C4.5演算法繼承了ID3演算法的優點,並在以下幾方面對ID3演算法進行了改進:
1) 用信息增益率來選擇屬性,克服了用信息增益選擇屬性時偏向選擇取值多的屬性的不足;
2) 在樹構造過程中進行剪枝;
3) 能夠完成對連續屬性的離散化處理;
4) 能夠對不完整數據進行處理。
C4.5演算法有如下優點:產生的分類規則易於理解,准確率較高。其缺點是:在構造樹的過程中,需要對數據集進行多次的順序掃描和排序,因而導致演算法的低效。此外,C4.5隻適合於能夠駐留於內存的數據集,當訓練集大得無法在內存容納時程序無法運行。
另外,無論是ID3還是C4.5最好在小數據集上使用,決策樹分類一般只試用於小數據。當屬性取值很多時最好選擇C4.5演算法,ID3得出的效果會非常差。
C. id3演算法是什麼
ID3演算法是一種貪心演算法,用來構造決策樹。ID3演算法起源於概念學習系統(CLS),以信息熵的下降速度為選取測試屬性的標准,即在每個節點選取還尚未被用來劃分的具有最高信息增益的屬性作為劃分標准,然後繼續這個過程,直到生成的決策樹能完美分類訓練樣例。
ID3演算法的背景
ID3演算法最早是由羅斯昆(J. Ross Quinlan)於1975年在悉尼大學提出的一種分類預測演算法,演算法的核心是「信息熵」。ID3演算法通過計算每個屬性的信息增益,認為信息增益高的是好屬性,每次劃分選取信息增益最高的屬性為劃分標准,重復這個過程,直至生成一個能完美分類訓練樣例的決策樹。
D. 信息增益准則為什麼對可取值數目較多的屬性有所偏好
從公式出發,信息增益是整個數據集的經驗熵與特徵A對整個數據集的經驗條件熵的差值,信息增益越大即經驗條件熵越小,那什麼情況下的屬性會有極小的的經驗條件熵呢?舉個極端的例子,如果將身份證號作為一個屬性,那麼,其實每個人的身份證號都是不相同的,也就是說,有多少個人,就有多少種取值,如果用身份證號這個屬性去劃分原數據集,那麼,原數據集中有多少個樣本,就會被劃分為多少個子集,這樣的話,會導致信息增益公式的第二項整體為0,雖然這種劃分毫無意義,但是從信息增益准則來講,這就是最好的劃分屬性。其實從概念來講,就一句話,信息增益表示由於特徵A而使得數據集的分類不確定性減少的程度,信息增益大的特徵具有更強的分類能力。
E. 5.10 決策樹與ID3演算法
https://blog.csdn.net/dorisi_h_n_q/article/details/82787295
決策樹(decision tree)是一個樹結構(可以是二叉樹或非二叉樹)。決策過程是從根節點開始,測試待分類項中相應的特徵屬性,並按照其值選擇輸出分支,直到到達葉子節點,將葉子節點存放的類別作為決策結果。
決策樹的關鍵步驟是分裂屬性。就是在某節點處按某一特徵屬性的不同劃分構造不同的分支,目標是讓各個分裂子集盡可能地「純」。即讓一個分裂子集中待分類項屬於同一類別。
簡而言之,決策樹的劃分原則就是:將無序的數據變得更加有序
分裂屬性分為三種不同的情況 :
構造決策樹的關鍵性內容是進行屬性選擇度量,屬性選擇度量(找一種計算方式來衡量怎麼劃分更劃算)是一種選擇分裂准則,它決定了拓撲結構及分裂點split_point的選擇。
屬性選擇度量演算法有很多,一般使用自頂向下遞歸分治法,並採用不回溯的貪心策略。這里介紹常用的ID3演算法。
貪心演算法(又稱貪婪演算法)是指,在對問題求解時,總是做出在當前看來是最好的選擇。也就是說,不從整體最優上加以考慮,所做出的是在某種意義上的局部最優解。
此概念最早起源於物理學,是用來度量一個熱力學系統的無序程度。
而在信息學裡面,熵是對不確定性的度量。
在1948年,香農引入了信息熵,將其定義為離散隨機事件出現的概率,一個系統越是有序,信息熵就越低,反之一個系統越是混亂,它的信息熵就越高。所以信息熵可以被認為是系統有序化程度的一個度量。
熵定義為信息的期望值,在明晰這個概念之前,我們必須知道信息的定義。如果待分類的事務可能劃分在多個分類之中,則符號x的信息定義為:
在劃分數據集之前之後信息發生的變化稱為信息增益。
知道如何計算信息增益,就可計算每個特徵值劃分數據集獲得的信息增益,獲得信息增益最高的特徵就是最好的選擇。
條件熵 表示在已知隨機變數的條件下隨機變數的不確定性,隨機變數X給定的條件下隨機變數Y的條
件熵(conditional entropy) ,定義X給定條件下Y的條件概率分布的熵對X的數學期望:
根據上面公式,我們假設將訓練集D按屬性A進行劃分,則A對D劃分的期望信息為
則信息增益為如下兩者的差值
ID3演算法就是在每次需要分裂時,計算每個屬性的增益率,然後選擇增益率最大的屬性進行分裂
步驟:1. 對當前樣本集合,計算所有屬性的信息增益;
是最原始的決策樹分類演算法,基本流程是,從一棵空數出發,不斷的從決策表選取屬性加入數的生長過程中,直到決策樹可以滿足分類要求為止。CLS演算法存在的主要問題是在新增屬性選取時有很大的隨機性。ID3演算法是對CLS演算法的改進,主要是摒棄了屬性選擇的隨機性。
基於ID3演算法的改進,主要包括:使用信息增益比替換了信息增益下降度作為屬性選擇的標准;在決策樹構造的同時進行剪枝操作;避免了樹的過度擬合情況;可以對不完整屬性和連續型數據進行處理;使用k交叉驗證降低了計算復雜度;針對數據構成形式,提升了演算法的普適性。
信息增益值的大小相對於訓練數據集而言的,並沒有絕對意義,在分類問題困難時,也就是說在訓練數據集經驗熵大的時候,信息增益值會偏大,反之信息增益值會偏小,使用信息增益比可以對這個問題進行校正,這是特徵選擇
的另一個標准。
特徵對訓練數據集的信息增益比定義為其信息增益gR( D,A) 與訓練數據集的經驗熵g(D,A)之比 :
gR(D,A) = g(D,A) / H(D)
sklearn的決策樹模型就是一個CART樹。是一種二分遞歸分割技術,把當前樣本劃分為兩個子樣本,使得生成的每個非葉子節點都有兩個分支,因此,CART演算法生成的決策樹是結構簡潔的二叉樹。
分類回歸樹演算法(Classification and Regression Trees,簡稱CART演算法)是一種基於二分遞歸分割技術的演算法。該演算法是將當前的樣本集,分為兩個樣本子集,這樣做就使得每一個非葉子節點最多隻有兩個分支。因此,使用CART
演算法所建立的決策樹是一棵二叉樹,樹的結構簡單,與其它決策樹演算法相比,由該演算法生成的決策樹模型分類規則較少。
CART分類演算法的基本思想是:對訓練樣本集進行遞歸劃分自變數空間,並依次建立決策樹模型,然後採用驗證數據的方法進行樹枝修剪,從而得到一顆符合要求的決策樹分類模型。
CART分類演算法和C4.5演算法一樣既可以處理離散型數據,也可以處理連續型數據。CART分類演算法是根據基尼(gini)系
數來選擇測試屬性,gini系數的值越小,劃分效果越好。設樣本集合為T,則T的gini系數值可由下式計算:
CART演算法優點:除了具有一般決策樹的高准確性、高效性、模式簡單等特點外,還具有一些自身的特點。
如,CART演算法對目標變數和預測變數在概率分布上沒有要求,這樣就避免了因目標變數與預測變數概率分布的不同造成的結果;CART演算法能夠處理空缺值,這樣就避免了因空缺值造成的偏差;CART演算法能夠處理孤立的葉子結點,這樣可以避免因為數據集中與其它數據集具有不同的屬性的數據對進一步分支產生影響;CART演算法使用的是二元分支,能夠充分地運用數據集中的全部數據,進而發現全部樹的結構;比其它模型更容易理解,從模型中得到的規則能獲得非常直觀的解釋。
CART演算法缺點:CART演算法是一種大容量樣本集挖掘演算法,當樣本集比較小時不夠穩定;要求被選擇的屬性只能產生兩個子結點,當類別過多時,錯誤可能增加得比較快。
sklearn.tree.DecisionTreeClassifier
1.安裝graphviz.msi , 一路next即可
ID3演算法就是在每次需要分裂時,計算每個屬性的增益率,然後選擇增益率最大的屬性進行分裂
按照好友密度劃分的信息增益:
按照是否使用真實頭像H劃分的信息增益
**所以,按先按好友密度劃分的信息增益比按真實頭像劃分的大。應先按好友密度劃分。
F. 決策樹之ID3演算法及其Python實現
決策樹之ID3演算法及其Python實現
1. 決策樹背景知識
??決策樹是數據挖掘中最重要且最常用的方法之一,主要應用於數據挖掘中的分類和預測。決策樹是知識的一種呈現方式,決策樹中從頂點到每個結點的路徑都是一條分類規則。決策樹演算法最先基於資訊理論發展起來,經過幾十年發展,目前常用的演算法有:ID3、C4.5、CART演算法等。
2. 決策樹一般構建過程
??構建決策樹是一個自頂向下的過程。樹的生長過程是一個不斷把數據進行切分細分的過程,每一次切分都會產生一個數據子集對應的節點。從包含所有數據的根節點開始,根據選取分裂屬性的屬性值把訓練集劃分成不同的數據子集,生成由每個訓練數據子集對應新的非葉子節點。對生成的非葉子節點再重復以上過程,直到滿足特定的終止條件,停止對數據子集劃分,生成數據子集對應的葉子節點,即所需類別。測試集在決策樹構建完成後檢驗其性能。如果性能不達標,我們需要對決策樹演算法進行改善,直到達到預期的性能指標。
??註:分裂屬性的選取是決策樹生產過程中的關鍵,它決定了生成的決策樹的性能、結構。分裂屬性選擇的評判標準是決策樹演算法之間的根本區別。
3. ID3演算法分裂屬性的選擇——信息增益
??屬性的選擇是決策樹演算法中的核心。是對決策樹的結構、性能起到決定性的作用。ID3演算法基於信息增益的分裂屬性選擇。基於信息增益的屬性選擇是指以信息熵的下降速度作為選擇屬性的方法。它以的資訊理論為基礎,選擇具有最高信息增益的屬性作為當前節點的分裂屬性。選擇該屬性作為分裂屬性後,使得分裂後的樣本的信息量最大,不確定性最小,即熵最小。
??信息增益的定義為變化前後熵的差值,而熵的定義為信息的期望值,因此在了解熵和信息增益之前,我們需要了解信息的定義。
??信息:分類標簽xi 在樣本集 S 中出現的頻率記為 p(xi),則 xi 的信息定義為:?log2p(xi) 。
??分裂之前樣本集的熵:E(S)=?∑Ni=1p(xi)log2p(xi),其中 N 為分類標簽的個數。
??通過屬性A分裂之後樣本集的熵:EA(S)=?∑mj=1|Sj||S|E(Sj),其中 m 代表原始樣本集通過屬性A的屬性值劃分為 m 個子樣本集,|Sj| 表示第j個子樣本集中樣本數量,|S| 表示分裂之前數據集中樣本總數量。
??通過屬性A分裂之後樣本集的信息增益:InfoGain(S,A)=E(S)?EA(S)
??註:分裂屬性的選擇標准為:分裂前後信息增益越大越好,即分裂後的熵越小越好。
4. ID3演算法
??ID3演算法是一種基於信息增益屬性選擇的決策樹學習方法。核心思想是:通過計算屬性的信息增益來選擇決策樹各級節點上的分裂屬性,使得在每一個非葉子節點進行測試時,獲得關於被測試樣本最大的類別信息。基本方法是:計算所有的屬性,選擇信息增益最大的屬性分裂產生決策樹節點,基於該屬性的不同屬性值建立各分支,再對各分支的子集遞歸調用該方法建立子節點的分支,直到所有子集僅包括同一類別或沒有可分裂的屬性為止。由此得到一棵決策樹,可用來對新樣本數據進行分類。
ID3演算法流程:
(1) 創建一個初始節點。如果該節點中的樣本都在同一類別,則演算法終止,把該節點標記為葉節點,並用該類別標記。
(2) 否則,依據演算法選取信息增益最大的屬性,該屬性作為該節點的分裂屬性。
(3) 對該分裂屬性中的每一個值,延伸相應的一個分支,並依據屬性值劃分樣本。
(4) 使用同樣的過程,自頂向下的遞歸,直到滿足下面三個條件中的一個時就停止遞歸。
??A、待分裂節點的所有樣本同屬於一類。
??B、訓練樣本集中所有樣本均完成分類。
??C、所有屬性均被作為分裂屬性執行一次。若此時,葉子結點中仍有屬於不同類別的樣本時,選取葉子結點中包含樣本最多的類別,作為該葉子結點的分類。
ID3演算法優缺點分析
優點:構建決策樹的速度比較快,演算法實現簡單,生成的規則容易理解。
缺點:在屬性選擇時,傾向於選擇那些擁有多個屬性值的屬性作為分裂屬性,而這些屬性不一定是最佳分裂屬性;不能處理屬性值連續的屬性;無修剪過程,無法對決策樹進行優化,生成的決策樹可能存在過度擬合的情況。
G. 什麼是ID3演算法
ID3演算法是由Quinlan首先提出的。該演算法是以資訊理論為基礎,以信息熵和信息增益度為衡量標准,從而實現對數據的歸納分類。以下是一些資訊理論的基本概念:
定義1:若存在n個相同概率的消息,則每個消息的概率p是1/n,一個消息傳遞的信息量為-Log2(1/n)
定義2:若有n個消息,其給定概率分布為P=(p1,p2…pn),則由該分布傳遞的信息量稱為P的熵,記為
。
定義3:若一個記錄集合T根據類別屬性的值被分成互相獨立的類C1C2..Ck,則識別T的一個元素所屬哪個類所需要的信息量為Info(T)=I(p),其中P為C1C2…Ck的概率分布,即P=(|C1|/|T|,…..|Ck|/|T|)
定義4:若我們先根據非類別屬性X的值將T分成集合T1,T2…Tn,則確定T中一個元素類的信息量可通過確定Ti的加權平均值來得到,即Info(Ti)的加權平均值為:
Info(X, T)=(i=1 to n 求和)((|Ti|/|T|)Info(Ti))
定義5:信息增益度是兩個信息量之間的差值,其中一個信息量是需確定T的一個元素的信息量,另一個信息量是在已得到的屬性X的值後需確定的T一個元素的信息量,信息增益度公式為:
Gain(X, T)=Info(T)-Info(X, T)
ID3演算法計算每個屬性的信息增益,並選取具有最高增益的屬性作為給定集合的測試屬性。對被選取的測試屬性創建一個節點,並以該節點的屬性標記,對該屬性的每個值創建一個分支據此劃分樣本.
數據描述
所使用的樣本數據有一定的要求,ID3是:
描述-屬性-值相同的屬性必須描述每個例子和有固定數量的價值觀。
預定義類-實例的屬性必須已經定義的,也就是說,他們不是學習的ID3。
離散類-類必須是尖銳的鮮明。連續類分解成模糊范疇(如金屬被「努力,很困難的,靈活的,溫柔的,很軟」都是不可信的。
足夠的例子——因為歸納概括用於(即不可查明)必須選擇足夠多的測試用例來區分有效模式並消除特殊巧合因素的影響。
屬性選擇
ID3決定哪些屬性如何是最好的。一個統計特性,被稱為信息增益,使用熵得到給定屬性衡量培訓例子帶入目標類分開。信息增益最高的信息(信息是最有益的分類)被選擇。為了明確增益,我們首先從資訊理論借用一個定義,叫做熵。每個屬性都有一個熵。
H. 簡述ID3演算法基本原理和步驟
1.基本原理:
以信息增益/信息熵為度量,用於決策樹結點的屬性選擇的標准,每次優先選取信息量最多(信息增益最大)的屬性,即信息熵值最小的屬性,以構造一顆熵值下降最快的決策樹,到葉子節點處的熵值為0。(信息熵 無條件熵 條件熵 信息增益 請查找其他資料理解)
決策樹將停止生長條件及葉子結點的類別取值:
①數據子集的每一條數據均已經歸類到每一類,此時,葉子結點取當前樣本類別值。
②數據子集類別仍有混亂,但已經找不到新的屬性進行結點分解,此時,葉子結點按當前樣本中少數服從多數的原則進行類別取值。
③數據子集為空,則按整個樣本中少數服從多數的原則進行類別取值。
步驟:
理解了上述停止增長條件以及信息熵,步驟就很簡單
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Id3.java
* Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
*
*/
package weka.classifiers.trees;
import weka.classifiers.Classifier;
import weka.classifiers.Sourcable;
import weka.core.Attribute;
import weka.core.Capabilities;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.;
import weka.core.RevisionUtils;
import weka.core.TechnicalInformation;
import weka.core.TechnicalInformationHandler;
import weka.core.Utils;
import weka.core.Capabilities.Capability;
import weka.core.TechnicalInformation.Field;
import weka.core.TechnicalInformation.Type;
import java.util.Enumeration;
/**
<!-- globalinfo-start -->
* Class for constructing an unpruned decision tree based on the ID3 algorithm. Can only deal with nominal attributes. No missing values allowed. Empty leaves may result in unclassified instances. For more information see: <br/>
* <br/>
* R. Quinlan (1986). Inction of decision trees. Machine Learning. 1(1):81-106.
* <p/>
<!-- globalinfo-end -->
*
<!-- technical-bibtex-start -->
* BibTeX:
* <pre>
* @article{Quinlan1986,
* author = {R. Quinlan},
* journal = {Machine Learning},
* number = {1},
* pages = {81-106},
* title = {Inction of decision trees},
* volume = {1},
* year = {1986}
* }
* </pre>
* <p/>
<!-- technical-bibtex-end -->
*
<!-- options-start -->
* Valid options are: <p/>
*
* <pre> -D
* If set, classifier is run in debug mode and
* may output additional info to the console</pre>
*
<!-- options-end -->
*
* @author Eibe Frank ([email protected])
* @version $Revision: 6404 $
*/
public class Id3
extends Classifier
implements TechnicalInformationHandler, Sourcable {
/** for serialization */
static final long serialVersionUID = -2693678647096322561L;
/** The node's successors. */
private Id3[] m_Successors;
/** Attribute used for splitting. */
private Attribute m_Attribute;
/** Class value if node is leaf. */
private double m_ClassValue;
/** Class distribution if node is leaf. */
private double[] m_Distribution;
/** Class attribute of dataset. */
private Attribute m_ClassAttribute;
/**
* Returns a string describing the classifier.
* @return a description suitable for the GUI.
*/
public String globalInfo() {
return "Class for constructing an unpruned decision tree based on the ID3 "
+ "algorithm. Can only deal with nominal attributes. No missing values "
+ "allowed. Empty leaves may result in unclassified instances. For more "
+ "information see: "
+ getTechnicalInformation().toString();
}
/**
* Returns an instance of a TechnicalInformation object, containing
* detailed information about the technical background of this class,
* e.g., paper reference or book this class is based on.
*
* @return the technical information about this class
*/
public TechnicalInformation getTechnicalInformation() {
TechnicalInformation result;
result = new TechnicalInformation(Type.ARTICLE);
result.setValue(Field.AUTHOR, "R. Quinlan");
result.setValue(Field.YEAR, "1986");
result.setValue(Field.TITLE, "Inction of decision trees");
result.setValue(Field.JOURNAL, "Machine Learning");
result.setValue(Field.VOLUME, "1");
result.setValue(Field.NUMBER, "1");
result.setValue(Field.PAGES, "81-106");
return result;
}
/**
* Returns default capabilities of the classifier.
*
* @return the capabilities of this classifier
*/
public Capabilities getCapabilities() {
Capabilities result = super.getCapabilities();
result.disableAll();
// attributes
result.enable(Capability.NOMINAL_ATTRIBUTES);
// class
result.enable(Capability.NOMINAL_CLASS);
result.enable(Capability.MISSING_CLASS_VALUES);
// instances
result.setMinimumNumberInstances(0);
return result;
}
/**
* Builds Id3 decision tree classifier.
*
* @param data the training data
* @exception Exception if classifier can't be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
data = new Instances(data);
data.deleteWithMissingClass();
makeTree(data);
}
/**
* Method for building an Id3 tree.
*
* @param data the training data
* @exception Exception if decision tree can't be built successfully
*/
private void makeTree(Instances data) throws Exception {
// Check if no instances have reached this node.
if (data.numInstances() == 0) {
m_Attribute = null;
m_ClassValue = Instance.missingValue();
m_Distribution = new double[data.numClasses()];
return;
}
// Compute attribute with maximum information gain.
double[] infoGains = new double[data.numAttributes()];
Enumeration attEnum = data.enumerateAttributes();
while (attEnum.hasMoreElements()) {
Attribute att = (Attribute) attEnum.nextElement();
infoGains[att.index()] = computeInfoGain(data, att);
}
m_Attribute = data.attribute(Utils.maxIndex(infoGains));
// Make leaf if information gain is zero.
// Otherwise create successors.
if (Utils.eq(infoGains[m_Attribute.index()], 0)) {
m_Attribute = null;
m_Distribution = new double[data.numClasses()];
Enumeration instEnum = data.enumerateInstances();
while (instEnum.hasMoreElements()) {
Instance inst = (Instance) instEnum.nextElement();
m_Distribution[(int) inst.classValue()]++;
}
Utils.normalize(m_Distribution);
m_ClassValue = Utils.maxIndex(m_Distribution);
m_ClassAttribute = data.classAttribute();
} else {
Instances[] splitData = splitData(data, m_Attribute);
m_Successors = new Id3[m_Attribute.numValues()];
for (int j = 0; j < m_Attribute.numValues(); j++) {
m_Successors[j] = new Id3();
m_Successors[j].makeTree(splitData[j]);
}
}
}
/**
* Classifies a given test instance using the decision tree.
*
* @param instance the instance to be classified
* @return the classification
* @throws if instance has missing values
*/
public double classifyInstance(Instance instance)
throws {
if (instance.hasMissingValue()) {
throw new ("Id3: no missing values, "
+ "please.");
}
if (m_Attribute == null) {
return m_ClassValue;
} else {
return m_Successors[(int) instance.value(m_Attribute)].
classifyInstance(instance);
}
}
/**
* Computes class distribution for instance using decision tree.
*
* @param instance the instance for which distribution is to be computed
* @return the class distribution for the given instance
* @throws if instance has missing values
*/
public double[] distributionForInstance(Instance instance)
throws {
if (instance.hasMissingValue()) {
throw new ("Id3: no missing values, "
+ "please.");
}
if (m_Attribute == null) {
return m_Distribution;
} else {
return m_Successors[(int) instance.value(m_Attribute)].
distributionForInstance(instance);
}
}
/**
* Prints the decision tree using the private toString method from below.
*
* @return a textual description of the classifier
*/
public String toString() {
if ((m_Distribution == null) && (m_Successors == null)) {
return "Id3: No model built yet.";
}
return "Id3 " + toString(0);
}
/**
* Computes information gain for an attribute.
*
* @param data the data for which info gain is to be computed
* @param att the attribute
* @return the information gain for the given attribute and data
* @throws Exception if computation fails
*/
private double computeInfoGain(Instances data, Attribute att)
throws Exception {
double infoGain = computeEntropy(data);
Instances[] splitData = splitData(data, att);
for (int j = 0; j < att.numValues(); j++) {
if (splitData[j].numInstances() > 0) {
infoGain -= ((double) splitData[j].numInstances() /
(double) data.numInstances()) *
computeEntropy(splitData[j]);
}
}
return infoGain;
}
/**
* Computes the entropy of a dataset.
*
* @param data the data for which entropy is to be computed
* @return the entropy of the data's class distribution
* @throws Exception if computation fails
*/
private double computeEntropy(Instances data) throws Exception {
double [] classCounts = new double[data.numClasses()];
Enumeration instEnum = data.enumerateInstances();
while (instEnum.hasMoreElements()) {
Instance inst = (Instance) instEnum.nextElement();
classCounts[(int) inst.classValue()]++;
}
double entropy = 0;
for (int j = 0; j < data.numClasses(); j++) {
if (classCounts[j] > 0) {
entropy -= classCounts[j] * Utils.log2(classCounts[j]);
}
}
entropy /= (double) data.numInstances();
return entropy + Utils.log2(data.numInstances());
}
/**
* Splits a dataset according to the values of a nominal attribute.
*
* @param data the data which is to be split
* @param att the attribute to be used for splitting
* @return the sets of instances proced by the split
*/
private Instances[] splitData(Instances data, Attribute att) {
Instances[] splitData = new Instances[att.numValues()];
for (int j = 0; j < att.numValues(); j++) {
splitData[j] = new Instances(data, data.numInstances());
}
Enumeration instEnum = data.enumerateInstances();
while (instEnum.hasMoreElements()) {
Instance inst = (Instance) instEnum.nextElement();
splitData[(int) inst.value(att)].add(inst);
}
for (int i = 0; i < splitData.length; i++) {
splitData[i].compactify();
}
return splitData;
}
/**
* Outputs a tree at a certain level.
*
* @param level the level at which the tree is to be printed
* @return the tree as string at the given level
*/
private String toString(int level) {
StringBuffer text = new StringBuffer();
if (m_Attribute == null) {
if (Instance.isMissingValue(m_ClassValue)) {
text.append(": null");
} else {
text.append(": " + m_ClassAttribute.value((int) m_ClassValue));
}
} else {
for (int j = 0; j < m_Attribute.numValues(); j++) {
text.append(" ");
for (int i = 0; i < level; i++) {
text.append("| ");
}
text.append(m_Attribute.name() + " = " + m_Attribute.value(j));
text.append(m_Successors[j].toString(level + 1));
}
}
return text.toString();
}
/**
* Adds this tree recursively to the buffer.
*
* @param id the unqiue id for the method
* @param buffer the buffer to add the source code to
* @return the last ID being used
* @throws Exception if something goes wrong
*/
protected int toSource(int id, StringBuffer buffer) throws Exception {
int result;
int i;
int newID;
StringBuffer[] subBuffers;
buffer.append(" ");
buffer.append(" protected static double node" + id + "(Object[] i) { ");
// leaf?
if (m_Attribute == null) {
result = id;
if (Double.isNaN(m_ClassValue)) {
buffer.append(" return Double.NaN;");
} else {
buffer.append(" return " + m_ClassValue + ";");
}
if (m_ClassAttribute != null) {
buffer.append(" // " + m_ClassAttribute.value((int) m_ClassValue));
}
buffer.append(" ");
buffer.append(" } ");
} else {
buffer.append(" checkMissing(i, " + m_Attribute.index() + "); ");
buffer.append(" // " + m_Attribute.name() + " ");
// subtree calls
subBuffers = new StringBuffer[m_Attribute.numValues()];
newID = id;
for (i = 0; i < m_Attribute.numValues(); i++) {
newID++;
buffer.append(" ");
if (i > 0) {
buffer.append("else ");
}
buffer.append("if (((String) i[" + m_Attribute.index()
+ "]).equals("" + m_Attribute.value(i) + "")) ");
buffer.append(" return node" + newID + "(i); ");
subBuffers[i] = new StringBuffer();
newID = m_Successors[i].toSource(newID, subBuffers[i]);
}
buffer.append(" else ");
buffer.append(" throw new IllegalArgumentException("Value '" + i["
+ m_Attribute.index() + "] + "' is not allowed!"); ");
buffer.append(" } ");
// output subtree code
for (i = 0; i < m_Attribute.numValues(); i++) {
buffer.append(subBuffers[i].toString());
}
subBuffers = null;
result = newID;
}
return result;
}
/**
* Returns a string that describes the classifier as source. The
* classifier will be contained in a class with the given name (there may
* be auxiliary classes),
* and will contain a method with the signature:
* <pre><code>
* public static double classify(Object[] i);
* </code></pre>
* where the array <code>i</code> contains elements that are either
* Double, String, with missing values represented as null. The generated
* code is public domain and comes with no warranty. <br/>
* Note: works only if class attribute is the last attribute in the dataset.
*
* @param className the name that should be given to the source class.
* @return the object source described by a string
* @throws Exception if the source can't be computed
*/
public String toSource(String className) throws Exception {
StringBuffer result;
int id;
result = new StringBuffer();
result.append("class " + className + " { ");
result.append(" private static void checkMissing(Object[] i, int index) { ");
result.append(" if (i[index] == null) ");
result.append(" throw new IllegalArgumentException("Null values "
+ "are not allowed!"); ");
result.append(" } ");
result.append(" public static double classify(Object[] i) { ");
id = 0;
result.append(" return node" + id + "(i); ");
result.append(" } ");
toSource(id, result);
result.append("} ");
return result.toString();
}
/**
* Returns the revision string.
*
* @return the revision
*/
public String getRevision() {
return RevisionUtils.extract("$Revision: 6404 $");
}
/**
* Main method.
*
* @param args the options for the classifier
*/
public static void main(String[] args) {
runClassifier(new Id3(), args);
}
}
J. 闡述ID3演算法處理連續型變數必須離散化的原因
使用所有沒有使用的屬性並計算與之相關的樣本熵值
選取其中熵值最小的屬性,生成包含該屬性的節點
D3演算法對數據的要求:
1) 所有屬性必須為離散量;
2) 所有的訓練例的所有屬性必須有一個明確的值;
3) 相同的因素必須得到相同的結論且訓練例必須唯一。