您的位置:首页 > 其它

(转)机器学习工具WEKA使用总结,包括算法选择、参数优化、属性选择

2016-11-16 16:20 417 查看


一、属性选择:


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:局部加权学习;

AdaBoostM1:AdaBoost方法;

AdditiveRegression:GBRT(Grandient Boosting Regression Tree)梯度下降回归树。是属于Boosting算法,也是将多分类器进行级联训练,后一级的分类器则更多关注前面所有分类器预测结果与实际结果的残差,在这个残差上训练新的分类器,最终预测时将残差级联相加。

AttributeSelectedClassifier:将属性选择和分类器集成设置,先进行属性选择、再进行分类或回归;

Bagging:bagging方法;

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。注意,没有常用的MultilayerPerceptron、RBFClassifier和RBFNetwork。

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之前,最好对数据进行随机排序。

原文地址:http://www.cnblogs.com/lutaitou/p/5818027.html   原文作者:鹿抬头
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息