[英]How to implement decision tree with c# (visual studio 2008) - Help
[英]using sql server 2008 decision tree to make predictions in C#
我正在创建一个C#应用程序我将通过一个简单的例子来解释我想要的东西:
考虑这个表:
name age reply choice
------+-------+-------+-------
John 10-20 yes apple
Kate 20-30 yes orange
Sam 10-20 yes apple
Peter 10-20 no ----
Tom 20-30 no ----
Mike 10-20 yes orange
我想为所有回复的人整理一个预测性的“年龄”决策树。 然后预测不回覆者的选择。
该表保存在SQL Server 2008数据库中。 SQL Server 2008中有一个功能可以做到这一点。 我搜索了Microsoft帮助网站,但我没有找到任何关于如何使用它的明确指南。
我如何在我的C#代码中使用它,任何人都得到了一步一步的指南?
这将达到目的:
-- create table
declare @t table (name varchar(50), age varchar(50), reply varchar(3), answer varchar(50))
insert @t (name, age, reply, answer)
values ('John', '10-20', 'yes', 'apple'),
('Kate', '20-30', 'yes', 'orange'),
('Sam', '10-20', 'yes', 'apple'),
('Peter', '10-20', 'no', '----'),
('Tom', '20-30', 'no', '----'),
('Mike', '10-20', 'yes', 'orange')
-- get answer
select t.name, t.age, t.reply, case t.reply when 'yes' then t.answer else w.answer end answer
from @t t
left join (
select age, answer
from (
select age, answer, count(*) cnt, row_number() over (partition by age order by count(*) desc) rnk
from @t
where reply = 'yes'
group by age, answer
) s
where rnk = 1
) w on t.age = w.age
只要找出每个年龄段提供的答案最多,然后选择答案,如果没有给出。
当两个答案之间有平局时,它只会选择一个。 我认为最先出现的那个并不能保证它会一直这样做。
请注意,如果您有一个答案为A:B = 55%:45%的组,那么所有没有答案的人都将得到答案A,因此您可以通过这样做来更改总体平均值。 你知道吗
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.