BookmarkSubscribeRSS Feed
sinmathstat
Fluorite | Level 6

Hi all,

 

I am new to this forum.

I have the following problem in SAS EM. The neighbors out of MBR node have  wrong orders. To illustrate the problem I wrote a simple program and I used proc pmbr to do the calculations.

 

data t1;
input y x1 x2;
id = _n_;
cards;
1 12 14
1 11 10
0 3 4
0 5 2
;
data t2;
input y x1 x2;

cards;
1 10 12
1 12 12
0 2 1
;
run;

proc dmdb data=t1 dmdbcat=work.temp;
	var  x1 x2;
	class y;
run;

proc pmbr data=t1 dmdbcat=work.temp k=1 method=scan outest=t1_out 
		neighbors ;
	target y;
	id id;
	score outfit=t2_fit data=t2 out=t2_out role=validation;
	
run;

proc print data=t2_out;
run;

proc pmbr data=t1 dmdbcat=work.temp k=2 method=scan outest=t1_out 
		neighbors ;
	target y;
	id id;
	score outfit=t2_fit data=t2 out=t2_out role=validation;
	
run;

proc print data=t2_out;
run;

proc pmbr data=t1 dmdbcat=work.temp k=3 method=scan outest=t1_out 
		neighbors ;
	target y;
	id id;
	score outfit=t2_fit data=t2 out=t2_out role=validation;
	
run;

proc print data=t2_out;
run;

as you see from the output the orders of neighbors are not correct, i.e. in the first output _n1 is 2 but the second output _n1 is 1. How I can produce the values of _n: in such a way that _n1 shows the first nn , _n2 shows the second nn, ...?

 

Thanks.

4 REPLIES 4
Reeza
Super User

I can't run those procs because I don't have EM, but couldn't you just sort the output dataset?

sinmathstat
Fluorite | Level 6
thanks for your reply.

unfortunately it is not possible to sort them.
WendyCzika
SAS Employee

I don't believe there is any ordering implied by the columns _N1, _N2,..  They are just showing the top K nearest neighbors, not necessarily ordered by the nearest to farthest since they all have equal weight when scoring.

sinmathstat
Fluorite | Level 6

Thanks for your reply.

 

I see. 

 

However wondering is there any technical difficulty (or benefit to not preserve ordering) for SAS to save _N1,_N2,... while preserving the orders? 

 

Because the ordered _N1, _N2,... has some benefits, e.g. customized weighted NN and/or easy way to find the optimum K, ...

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2495 views
  • 0 likes
  • 3 in conversation