简体   繁体   English

Matlab遗传算法如何利用分类精度作为适应度函数

[英]Genetic algorithm with matlab how to use classification accuracy as fitness function

I have a problem which I want to solve with matlab Genetic algorithm toolbox and I dont know how to solve it. 我有一个要使用Matlab遗传算法工具箱解决的问题,我不知道如何解决。 I want to calculate 3 coefficient in a formula in a way that it maximizes a function which is the classification accuracy of a SVM classification model. 我想在公式中计算3系数,以使其最大化一个函数,该函数即SVM分类模型的分类精度。 the formula of the coefficients is a*A+b*B+c*C in which a,b,c are the coefficients which I want to find their optimized value and A,B,C are the value of 3 attributes of the dataset. 系数的公式是a * A + b * B + c * C,其中a,b,c是我想找到其优化值的系数,A,B,C是数据集的3个属性的值。 I also have the constraint a+b+c=1 and a,b,c>0 我也有约束a + b + c = 1和a,b,c> 0

How should I use genetic algorithm to solve this problem? 我应该如何使用遗传算法解决这个问题?

You first need to randomly generate an initial feasible solutions, as the first generation. 首先,您需要像第一代一样随机生成初始可行的解决方案。

Each of these feasible solutions should satisfy a + b + c = 1 and a, b, c > 0 . 这些可行解均应满足a + b + c = 1a, b, c > 0

Then based on your fitness function, evaluation each of the answers, and choose the better ones as "parents". 然后根据您的适应度函数,评估每个答案,然后选择更好的答案作为“父母”。 Apply GA techniques such as "cross-over" or "mutation" on these parents, to yield a group of offspring, as the next generation. 在这些亲本上应用遗传算法,例如“杂交”或“变异”,以产生一组后代,作为下一代。

Repeat this process for a set amount of times, say, for 500 generation. 重复此过程一定的时间,例如500代。

For example, you could define a variable fitness , the higher value means its corresponding candidate is a more suitable solution. 例如,您可以定义一个变量fitness ,值越高,意味着其对应的候选者是更合适的解决方案。 Since you are maximizing this function, then: 由于您正在最大限度地利用此功能,因此:

fitness = a * A + b * B + c * C 适合度= a * A + b * B + c * C

In each of your GA operations (cross-over, mutation, etc), remember to always yield new candidates that satisfy your initial constraints ( a + b + c = 1 and a, b, c > 0 ). 在您的每项GA操作(交叉,变异等)中,请记住始终产生满足初始约束( a + b + c = 1a, b, c > 0 )的新候选对象。

Based on my experience one of the best solution for it is implementing the GA of MATLAB. 根据我的经验,最好的解决方案之一就是实现MATLAB的GA。 The GA toolbox is generated to looking for minimum of such this function but by using symmetry, it leads to maximize of the function which your are looking for. GA工具箱的产生是为了寻找这种功能的最小值,但是通过使用对称性,它将导致您正在寻找的功能的最大化。 Follow these steps: 跟着这些步骤:

  • A,B, C = input data A,B,C =输入数据
  • Normalize a,b,c which leads to a+b+c=1 归一化a,b,c导致a + b + c = 1
  • Your fitness function is a A+b B+c*C and define it 您的适应度函数是A + b B + c * C并定义它
  • Define nvars which for you is 3 定义为您的nvars 3
  • Put LB (lower boundary) in your case [0 0 0] which is a,b,c>0 在您的情况下[0 0 0]放入LB(下边界),即a,b,c> 0
  • Run [x, fval]=ga(...) there for x will be final result x=[abc] 运行[x,fval] = ga(...),因为x将是最终结果x = [abc]

If there were any question please e-mail me for more help: mahdigh242@yahoo.com 如有任何疑问,请给我发送电子邮件以获取更多帮助:mahdigh242@yahoo.com

Hope the best 希望最好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM