在给定一组嵌套规则的情况下决定值的最合乎逻辑的方法是什么?我们如何存储它?
我需要实现对我来说看起来像决策树的东西(尽管搜索该术语会返回有关找出决策过程中的影响因素的帖子 - 这不是我所追求的)。
我正在构建的系统将制定保修期,以便根据某些标准进行产品安装。要求是创建一组可能的向量(例如安装间距、轮廓、位置、材料类型等...),并将这些向量由用户组装成树结构:
-- Profile == corrugate (warranty = 20 years)
-- Pitch >= 0 && < 5 (warranty = 2 years)
-- Pitch >= 5 && < 20 (warranty = 10 years)
-- Environment == coastal && distance <= 500 meters (warranty 2 years)
这是一个简单的情况,但是理论上来说,当需要计算出保修期时,我可以遍历这棵树,然后根据所提供的信息选择树产生的最低值。
现在我可以明显地看到它作为树存储在数据库中(它是一个 Rails 应用程序),并且只需编写一些方法来遍历树并做出决定,但我想知道是否有更好的方法来解决这个问题?
当我还实现另一个决策树时,我将不得不在项目稍后重复自己,该决策树将决定保修申请是否需要我们的保修团队进一步审核。在这种情况下,每个节点的结果将只是 true 或 false。
鉴于它是应用程序的一个非常重要的部分,我希望第一次就能获得正确的结构:)并且也许可以在此过程中学习一些新东西:)
I'm needing to implement what to me looks like a decision tree (though searching on that term returns posts on finding out influencing factors in a decision process - which isn't what I'm after).
The system I'm building will be working out warranty periods to give a product installation based upon some criteria. The requirement is for the creation of a set of possible vectors (e.g. Installation Pitch, Profile, location, material type etc...) and for those vectors to be assembled by the user into a tree structure:
-- Profile == corrugate (warranty = 20 years)
-- Pitch >= 0 && < 5 (warranty = 2 years)
-- Pitch >= 5 && < 20 (warranty = 10 years)
-- Environment == coastal && distance <= 500 meters (warranty 2 years)
This is a simple case, but the theory is that I can then walk this tree when it comes time to figure out a warranty period, and then choose the lowest value that the tree produces given the supplied information.
Right now I can sensibly see this being stored as a tree in the database (it's a Rails app) and just writing some method to walk the tree and decide, but I wanted to know if there is a better way to approach this problem?
I'm going to have to repeat myself later in the project when I also implement another decision tree that will decide whether a warranty application needs further moderation by our warranty team. In that case the outcome from each node will just be true or false.
Seeing as it's a pretty crucial part of the app I'd like to get the structure right first time :) And perhaps learn something new along the way :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为一棵树(或多棵树——因为在做出决定之前一次只能比较一个向量元素)可以非常直观地转换这些数据。可能有一种更紧凑的方法来做到这一点,但是如果其他人将来会查看此代码,树方法将帮助他们维护它。
I think a tree (or multiple trees--since you can only compare one vector element at a time before making a decision) translates this data very intuitively. There may be a more compact way of doing it, but if anyone else will be looking at this code in the future, the tree method will help them to maintain it.
我认为这就是您正在寻找的:
Ruby 中的决策树 - 它甚至使用类似的例子是,根据一些输入的数据,做出选择加入或选择退出某个计划的决定。因此,根据您的示例 - 使用某些标准来决定是否可以使用保修。
它使用了一种名为“决策树”的宝石
希望有所帮助。
I think this what you are looking for:
Decision Trees in Ruby - it even uses a similar example, based on some feed in data, make a decision to opt-in or opt-out into a program. So based on your example - using certain criteria decide if the warranty can be used or not.
It uses a gem called 'decisiontree'
Hope that helps.