機器學習工具WEKA使用總結,包括算法選擇、參數優化、屬性選擇


一、屬性選擇:

1、理論知識:

見以下兩篇文章:

數據挖掘中的特征選擇算法綜述及基於WEKA的性能比較_陳良龍

數據挖掘中約簡技術與屬性選擇的研究_劉輝

2、weka中的屬性選擇

2.1評價策略(attribute evaluator)

總的可分為filter和wrapper方法,前者注重對單個屬性進行評價,后者側重對特征子集進行評價。

Wrapper方法有:CfsSubsetEval

Filter方法有:CorrelationAttributeEval

2.1.1 Wrapper方法:

(1)CfsSubsetEval

根據屬性子集中每一個特征的預測能力以及它們之間的關聯性進行評估,單個特征預測能力強且特征子集內的相關性低的子集表現好。

Evaluates the worth of a subset of attributes by considering the individual predictive ability of each feature along with the degree of redundancy between them.Subsets of features that are highly correlated with the class while having low intercorrelation are preferred.

For more information see:

M. A. Hall (1998). Correlation-based Feature Subset Selection for Machine Learning. Hamilton, New Zealand.

(2)WrapperSubsetEval

Wrapper方法中,用后續的學習算法嵌入到特征選擇過程中,通過測試特征子集在此算法上的預測性能來決定其優劣,而極少關注特征子集中每個特征的預測性能。因此,並不要求最優特征子集中的每個特征都是最優的。

Evaluates attribute sets by using a learning scheme. Cross validation is used to estimate the accuracy of the learning scheme for a set of attributes.

For more information see:

Ron Kohavi, George H. John (1997). Wrappers for feature subset selection. Artificial Intelligence. 97(1-2):273-324.

2.1.2 Filter方法:

如果選用此評價策略,則搜索策略必須用Ranker。

(1)CorrelationAttributeEval

根據單個屬性和類別的相關性進行選擇。

Evaluates the worth of an attribute by measuring the correlation (Pearson's) between it and the class.

Nominal attributes are considered on a value by value basis by treating each value as an indicator. An overall correlation for a nominal attribute is arrived at via a weighted average.

(2)GainRatioAttributeEval

根據信息增益比選擇屬性。

Evaluates the worth of an attribute by measuring the gain ratio with respect to the class.

GainR(Class, Attribute) = (H(Class) - H(Class | Attribute)) / H(Attribute).

(3)InfoGainAttributeEval

根據信息增益選擇屬性。

Evaluates the worth of an attribute by measuring the information gain with respect to the class.

InfoGain(Class,Attribute) = H(Class) - H(Class | Attribute).

(4)OneRAttributeEval

根據OneR分類器評估屬性。

Class for building and using a 1R classifier; in other words, uses the minimum-error attribute for prediction, discretizing numeric attributes. For more information, see:

R.C. Holte (1993). Very simple classification rules perform well on most commonly used datasets. Machine Learning. 11:63-91.

(5)PrincipalComponents

主成分分析(PCA)。

Performs a principal components analysis and transformation of the data. Use in conjunction with a Ranker search. Dimensionality reduction is accomplished by choosing enough eigenvectors to account for some percentage of the variance in the original data---default 0.95 (95%). Attribute noise can be filtered by transforming to the PC space, eliminating some of the worst eigenvectors, and then transforming back to the original space.

(6)ReliefFAttributeEval

根據ReliefF值評估屬性。

Evaluates the worth of an attribute by repeatedly sampling an instance and considering the value of the given attribute for the nearest instance of the same and different class. Can operate on both discrete and continuous class data.

For more information see:

Kenji Kira, Larry A. Rendell: A Practical Approach to Feature Selection. In: Ninth International Workshop on Machine Learning, 249-256, 1992.

Igor Kononenko: Estimating Attributes: Analysis and Extensions of RELIEF. In: European Conference on Machine Learning, 171-182, 1994.

Marko Robnik-Sikonja, Igor Kononenko: An adaptation of Relief for attribute estimation in regression. In: Fourteenth International Conference on Machine Learning, 296-304, 1997.

(7)SymmetricalUncertAttributeEval

根據屬性的對稱不確定性評估屬性。

Evaluates the worth of an attribute by measuring the symmetrical uncertainty with respect to the class.

 SymmU(Class, Attribute) = 2 * (H(Class) - H(Class | Attribute)) / H(Class) + H(Attribute).

2.2搜索策略(Search Method)

2.2.1和評價策略中的wrapper方法對應

(1)BestFirst

最好優先的搜索策略。是一種貪心搜索策略。

Searches the space of attribute subsets by greedy hillclimbing augmented with a backtracking facility. Setting the number of consecutive non-improving nodes allowed controls the level of backtracking done. Best first may start with the empty set of attributes and search forward, or start with the full set of attributes and search backward, or start at any point and search in both directions (by considering all possible single attribute additions and deletions at a given point).

(2)ExhaustiveSearch

窮舉搜索所有可能的屬性子集。

Performs an exhaustive search through the space of attribute subsets starting from the empty set of attrubutes. Reports the best subset found.

(3)GeneticSearch

基於Goldberg在1989年提出的簡單遺傳算法進行的搜索。

Performs a search using the simple genetic algorithm described in Goldberg (1989).

For more information see:

David E. Goldberg (1989). Genetic algorithms in search, optimization and machine learning. Addison-Wesley.

(4)GreedyStepwise

向前或向后的單步搜索。

Performs a greedy forward or backward search through the space of attribute subsets. May start with no/all attributes or from an arbitrary point in the space. Stops when the addition/deletion of any remaining attributes results in a decrease in evaluation. Can also produce a ranked list of attributes by traversing the space from one side to the other and recording the order that attributes are selected.

(5)RandomSearch

隨機搜索。

Performs a Random search in the space of attribute subsets. If no start set is supplied, Random search starts from a random point and reports the best subset found. If a start set is supplied, Random searches randomly for subsets that are as good or better than the start point with the same or or fewer attributes. Using RandomSearch in conjunction with a start set containing all attributes equates to the LVF algorithm of Liu and Setiono (ICML-96).

For more information see:

H. Liu, R. Setiono: A probabilistic approach to feature selection - A filter solution. In: 13th International Conference on Machine Learning, 319-327, 1996.

(6)RankSearch

用一個評估器計算屬性判據值並排序。

Uses an attribute/subset evaluator to rank all attributes. If a subset evaluator is specified, then a forward selection search is used to generate a ranked list. From the ranked list of attributes, subsets of increasing size are evaluated, ie. The best attribute, the best attribute plus the next best attribute, etc.... The best attribute set is reported. RankSearch is linear in the number of attributes if a simple attribute evaluator is used such as GainRatioAttributeEval. For more information see:

Mark Hall, Geoffrey Holmes (2003). Benchmarking attribute selection techniques for discrete class data mining. IEEE Transactions on Knowledge and Data Engineering. 15(6):1437-1447.

2.2.2和評價策略中的filter方法對應

(1)Ranker :

對屬性的判據值進行排序,和評價策略中的Filter方法結合使用。

Ranks attributes by their individual evaluations. Use in conjunction with attribute evaluators (ReliefF, GainRatio, Entropy etc).

3、我的總結

針對某一算法及其參數設置,選用WrapperSubsetEval評價策略和ExhaustiveSearch搜索策略,能夠保證找到適合該算法即參數設置的最優屬性子集。但其計算時間較長,並且隨着屬性個數的增多成指數級增長。

二、參數優化

針對某一特定算法,進行參數優化有以下三種方法:CVParameterSelection、GridSearch、MultiSearch。

1、CVParameterSelection

采用交叉驗證的方法,對參數進行優化選擇。

優點:

可以對任意數量的參數進行優化選擇;

缺點:

①參數太多時,可能造成參數組合數量的爆炸性增長;②只能優化分類器的直接參數,不能優化其嵌入的參數,比如可以優化weka.classifiers.functions.SMO里的參數C,但不能優化weka.classifiers.meta.FilteredClassifier中的嵌入算法weka.classifiers.functions.SMO里的參數C。

示例:優化J48算法的置信系數C

①    載數據集;

②    選擇 weka.classifiers.meta.CVParameterSelection作為分類器;

③    選擇weka.classifiers.trees.J48作為②的基分類器;

④    參數優化的字符串:C 0.1 0.5 5(優化參數C,范圍是從0.1至0.5,步距是0.5/5=0.1)

⑤    進行運算,得到如下圖所示的結果(最后一行是優化的參數):

 

2、GridSearch

采用網格搜索,而不是試驗所有的參數組合,進行參數的選擇。

優點:

①理論上,相同的優化范圍及設置,GridSearch應該比CVParameterSelection要快;②不限於優化分類器的直接參數,也可以優化其嵌入算法的參數;③優化的2個參數中,其中一個可以是filter里的參數,所以需要在屬性表達式中加前綴classifier.或filter.;④支持范圍的自動擴展。

缺點:

最多優化2個參數。

示例:優化以RBFKernel為核的SMO算法的參數

①    加載數據集;

②    選擇GridSearch為Classifier;

③    選擇GridSearch的Classifier為weka.classifiers.functions.SMO ,kernel為weka.classifiers.functions.supportVector.RBFKernel。

④    設置X參數。XProperty:classifier.c,XMin:1,XMax:16,XStep:1,XExpression:I。這的意思是:選擇參數c,其范圍是1到16,步長1。

⑤    設置Y參數。YProperty:"classifier.kernel.gamma,YMin:-5,YMax:2,YStep:1,YBase:10,YExpression: pow(BASE,I)。這的意思是:選擇參數kernel.gamma,其范圍是10-5,10-4,…,102

⑥    輸出如下(最后一行是優化的參數):

 

3、MultiSearch

類似網格參數,但更普通更簡單。

優點:

①不限於優化分類器的直接參數,也可以優化其嵌入算法的參數或filter的參數;②支持任意數量的參數優化;

缺點:

不支持自動擴展邊界。

4、我的總結

①如果需要優化的參數不大於2個,選用gridsearch,並且設置邊界自動擴展;

②如果需要優化的參數大於2個,選用MultiSearch;

③如果優化分類器的直接參數,且參數數量不大於2個,也可以考慮用CVParameterSelection。

三、meta-Weka的算法

1、算法及描述

LocalWeightedLearning局部加權學習;

AdaBoostM1AdaBoost方法;

AdditiveRegressionGBRT(Grandient Boosting Regression Tree)梯度下降回歸樹。是屬於Boosting算法,也是將多分類器進行級聯訓練,后一級的分類器則更多關注前面所有分類器預測結果與實際結果的殘差,在這個殘差上訓練新的分類器,最終預測時將殘差級聯相加。

AttributeSelectedClassifier將屬性選擇和分類器集成設置,先進行屬性選擇、再進行分類或回歸;

Baggingbagging方法;

ClassificationViaRegression:用回歸的方法進行分類;

LogitBoost:是一種boosting算法,用回歸進行分類。

MultiClassClassifier使用兩類分類器進行多類分類的方法。

RondomCommittee:隨機化基分類器結果的平均值作為結果。

RandomSubspace;

FilterClassifier將過濾器和分類器集成設置,先進行過濾、再進行分類或回歸;(autoweka中沒有)

MultiScheme在所指定的多個分類器或多種參數配置中,選擇最優的一個。(猶如experiment)(autoweka中沒有)

RandomizableFitteredClassifier:是FilterClassifier的變體,對於RondomCommittee的ensemble classifiers是很有用的。要求不管是filter還是classifier都支持randomizable接口。(autoweka中沒有)

Vote

Stacking

2、我的總結

Meta提供了很多以基分類器為輸入的方法,其中:

①AdaBoostM1和Bagging方法是常用的meta方法;

②MultiScheme和experiment的功能類似;

③AttributeSelectedClassifier將屬性選擇和分類器集成設置,比較方便。

四、Auto-WEKA

Auto-WEKA支持屬性、算法、參數的自動選擇。

1、屬性選擇

屬性選擇作為數據的預處理步驟,在分類或回歸前運行。

 

Auto-WEKA中屬性選擇的評價策略和搜索策略如上圖所示。其中標*的是搜索策略,其余的是評價策略。可見,不包括WrapperSubsetEval評價策略和ExhaustiveSearch搜索策略組合的完備搜索。

2、算法選擇

 

上圖是Auto-WEKA中包括的分類或回歸算法,共39種:27種基分類器、10種meta分類器、2種ensemble分類器。其中,meta分類器可以選任意一種基分類器作為輸入,ensemble分類器可以使用最多5種基分類器作為輸入。

27種基分類器包括:

Bayes里的3種:BayesNet、NaiveBayes、和NaiveBayesMultinomial;

Functions里的9種:GaussianProcesses、LinearRegression、LogisticRegression、SingleLayerPerceptron、SGD、SVM、SimpleLinearRegression、SimpleLogistivRegression、VotedPerceptron。注意,沒有常用的MultilayerPerceptronRBFClassifierRBFNetwork

Lazy里的2種:KNN、KStar(*)。

Rules里的6種:DecisionTables、RIPPER、M5Rules、1-R、PART、0-R。

Trees里的7種:DecisionStump、C4.5DecisionTrees、LogisticModelTree、M5Tree、RandomForest、RondomTree、REPTree。

10種meta分類器:

LocalWeightedLearning:局部加權學習;

AdaBoostM1:AdaBoost方法;

AdditiveRegression:GBRT(Grandient Boosting Regression Tree)梯度下降回歸樹。是屬於Boosting算法,也是將多分類器進行級聯訓練,后一級的分類器則更多關注前面所有分類器預測結果與實際結果的殘差,在這個殘差上訓練新的分類器,最終預測時將殘差級聯相加。

AttributeSelectedClassifier:將屬性選擇和分類器集成設置,先進行屬性選擇、再進行分類或回歸;

Bagging:bagging方法;

ClassificationViaRegression:用回歸的方法進行分類;

LogitBoost:是一種boosting算法,用回歸進行分類。

MultiClassClassifier:使用兩類分類器進行多類分類的方法。

RondomCommittee:隨機化基分類器結果的平均值作為結果。

RandomSubspace。

2種ensamble方法:

Vote和stacking。

3、我的總結

Auto-Weka有兩點不足:

①屬性選擇里不包括WrapperSubsetEval評價策略和ExhaustiveSearch搜索策略組合的完備搜索。

②注意,沒有常用的MultilayerPerceptron、RBFClassifier和RBFClassifier。

五、總結

1、屬性、算法、參數的選擇及優化

對於一個不熟悉的數據集合,想要快速獲取最佳的分類器、參數設置、屬性子集,可以按照以下步驟:

Auto-Weka選擇范圍是大部分分類器和屬性選擇策略,但不包括MultilayerPerceptron、RBFClassifier和RBFNetwork等分類器和完備搜索的屬性選擇策略;

補充常用分類器及其參數、屬性的選擇:針對①的不足,選用常用分類器進行屬性選擇和參數優化,這些常用分類器有MultilayerPerceptron、RBFClassifier、RBFClassifier、BayesNet、NaïveBayes、SMO或SVM、linerRegression,選用其中一種,或逐一試驗,進行③④⑤;

特定分類器的屬性選擇:選擇explorer中的“Select attributes”選項卡,屬性評估策略(Attribute Evaluator)選擇WrapperSubsetEval,搜索策略(SearchMethod)選擇ExhaustiveSearch,WrapperSubsetEval中的Classifier選擇參數優化算法(CVParameterSelection、GridSearch、MultiSearch),比如CVParameterSelection,選擇CVParameterSelection的Classifier為特定分類器,進行參數優化的相關配置;運算后,得到Selected Attributes,暫時記下來;

特定分類器的參數優化:在Preprocess中預處理數據僅使用③中的SelectedAttributes,在Classifier中選擇和③中相同的參數優化算法及其配置,包括分類器;

結果:③的SelectedAttributes和④的參數優化值就是特定分類器最佳的屬性子集和參數設置。

2、特別注意

2.1數據標准化

有些算法,在進行運算前,要求必須對數據進行標准化處理,而有些不用。

數據標准化的優點:

①  避免數值問題。

②  使網絡快速的收斂。

③  統一評價標准,便於不同單位或量級的指標能夠進行比較和加權。

④  bp中常采用sigmoid函數作為轉移函數,歸一化能夠防止凈輸入絕對值過大引起的神經元輸出飽和現象 。

⑤  保證輸出數據中數值小的不被吞食 。

數據標准化的常用方法:

①  Min-max 標准化     

min-max標准化方法是對原始數據進行線性變換,映射到區間[0,1]或[-1,1]。

②  Z-Score標准化

Z-Score標准化方法適用於屬性A的最大值和最小值未知的情況,或有超出取值范圍的離群數據的情況。這種方法基於原始數據的均值(mean)和標准差(standard deviation)進行數據的標准化,新數據=(原數據-均值)/標准差

③  方法選取

如果數據分布均勻,則用Min-max方法。如果有離群數據,最好找出來刪掉,再用Min-max方法,如果不好找出來,則用z-score方法。

何種情況下,要進行標准化:

主要看模型是否具有伸縮不變性。一般來說,神經網絡類和支持向量機類的算法都需要,並且最好是標准化到[-1,1]。決策樹類的一般不需要。

如果不確定,就標准化到[-1,1]或Z-Score吧。

2.2TestOptions的選擇

主要是UseTrainingSet和CrossValidation的選擇。

一般,根據算法的說明,可以判斷出是否需要CrossValidation。有一個小技巧,如果算法的參數設置中有交叉驗證的折數(numFolds)和隨機選取的種子(seed),則不需要CrossValidation;否則,需要CrossValidation。

CrossValidation之前,最好對數據進行隨機排序。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM