[R] KNN

Jim Lemon drjimlemon at gmail.com
Thu Feb 25 11:15:23 CET 2016


Hi Alnazer,
I'm not surprised that it didn't do what you expected. Even if I clean
up the code so that it will actually run:

majorityGuessing<-function(trainingData,categories) {
 GuessMPG<-sample(1:length(categories),nrow(trainingData),replace=TRUE)
 return(GuessMPG)
}

and call it like this (assuming that you are trying to do something
like guessing MPG from the number of cylinders):

auto<-read.csv("auto.csv")
majorityGuessing(auto$MPG,unique(auto$CYLINDERS))

the result is just a sample of 398 integers ranging from 1 to 5, which
is not even a guess. Unfortunately, I can't work out what metric you
want to select "nearest neighbors", but perhaps someone else can.

Jim

On Thu, Feb 25, 2016 at 5:30 PM, Alnazer Elbedairy
<alnazer.elbedairy at gmail.com> wrote:
> Dear Jim
> thanks you for your kind help.
> KNN - is K- Nearest Neighbor, is a technique used in Machine Learning.
> attached you will find a CSV file dataset, my question is :
> use the attached Dataset, Use majority guessing technique to evaluate KNN ?
> this is the solution I came up with, but I didn't work :-
> majorityGuessing <- function(trainingData,categories)
> {GuessMPG <- sample(1:length (categories-1, nrow(testingData),replace=T)
> return(GuessMPG)
>
>
>
> On Wed, Feb 24, 2016 at 8:18 PM, Jim Lemon <drjimlemon at gmail.com> wrote:
>>
>> Hi Alnazar,
>> I looked at your question yesterday and was unable to find what a
>> "majority guessing" function is. I think it may be related to the
>> "Pandemonium" model of decision making, but that doesn't get me very
>> far. Could you give us a hint as to what this function is?
>>
>>
>
> On Wed, Feb 24, 2016 at 8:18 PM, Jim Lemon <drjimlemon at gmail.com> wrote:
>>
>> Hi Alnazar,
>> I looked at your question yesterday and was unable to find what a
>> "majority guessing" function is. I think it may be related to the
>> "Pandemonium" model of decision making, but that doesn't get me very
>> far. Could you give us a hint as to what this function is?
>>
>> Jim
>>
>>
>> On Wed, Feb 24, 2016 at 7:02 AM, Alnazer <alnazer.elbedairy at gmail.com>
>> wrote:
>> > How I can use majority guessing function to evaluate KNN, if I have data
>> > saved in CSV file
>> >
>> > Alnazer Elbedairy
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list