[R] KNN

2016-02-24 Thread Alnazer
How I can use majority guessing function to evaluate KNN, if I have data saved 
in CSV file

Alnazer Elbedairy

__
R-help@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.


Re: [R] KNN

2016-02-25 Thread Alnazer
Appreciated Jim.

Alnazer Elbedairy


> On Feb 25, 2016, at 4:15 AM, Jim Lemon  wrote:
> 
> 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
>  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  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  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 
>>> wrote:
>>>> How I can use majority guessing function to evaluate KNN, if I have data
>>>> saved in CSV file
>>>> 
>>>> Alnazer Elbedairy
>>>> 
>>>> __
>>>> R-help@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.
>> 
>> 

[[alternative HTML version deleted]]

__
R-help@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.


[R] majority guessing

2016-02-22 Thread Alnazer Elbedairy
dear there
what the steps I can find the knn by using majority guessing.
thanks.

[[alternative HTML version deleted]]

__
R-help@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.


[R] Normalization in R

2016-02-24 Thread Alnazer Elbedairy
Dear all
anyone know the function or syntax to get the Normalization for Data ?
thanks

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] KNN

2016-02-24 Thread Alnazer Elbedairy
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  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  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 
> wrote:
> > How I can use majority guessing function to evaluate KNN, if I have data
> saved in CSV file
> >
> > Alnazer Elbedairy
> >
> > __
> > R-help@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.
>
__
R-help@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.


Re: [R] KNN

2016-02-25 Thread Alnazer Elbedairy
Dear All
Divide (same dataset) into 10 folds
fold1 <- nautaData[1:39]
fold2 <- nautaData[40:79]
fold3 <- nautaData[80:119]
fold4 <- nautaData[120:159]
fold5 <- nautaData[160:199]
fold6 <- nautaData[200:239]
fold7 <- nautaData[240:279]
fold8 <- nautaData[280:319]
fold9 <- nautaData[320:359]
fold10 <- nautaData[360:398]
 then
1- conduct 10 fold cross validation on KNN and magorityGuessing function
2- print classification error for both KNN and MPG for every fold
3- print confusion matrix for KNN during each fold
 thank you for help

On Thu, Feb 25, 2016 at 7:32 AM, Ben Tupper  wrote:

> Hi,
>
> Do the knn() or knn1() functions in the 'class' package serve your purpose?
>
> https://cran.r-project.org/web/packages/class/index.html
>
> Ben
>
> > On Feb 25, 2016, at 9:49 AM, David L Carlson  wrote:
> >
> > Perhaps Alnazer is trying to implement "majority vote" kNN:
> >
> >> From Wikipedia
> > (https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm):
> >
> > In k-NN classification, the output is a class membership. An object is
> classified by a majority vote of its neighbors, with the object being
> assigned to the class most common among its k nearest neighbors (k is a
> positive integer, typically small). If k = 1, then the object is simply
> assigned to the class of that single nearest neighbor.
> >
> > But as Jim said, your function does not do this. It does not even run
> kNN.
> >
> > -
> > David L Carlson
> > Department of Anthropology
> > Texas A&M University
> > College Station, TX 77840-4352
> >
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jim
> Lemon
> > Sent: Thursday, February 25, 2016 4:15 AM
> > To: Alnazer Elbedairy
> > Cc: r-help mailing list
> > Subject: Re: [R] KNN
> >
> > 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
> >  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 
> 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 
> 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 
> >>> wrote:
> >>>> How I can use majority guessing function to evaluate KNN, if I have
> data
> >>>> saved in CSV file
> >&

[R] PDF form Rstudio

2016-02-25 Thread Alnazer Elbedairy
Dear All
I did the following steps to get a PDF file from Rstudio
1- activate Rmarkdown
2- save file as (name.Rmd)
3- use chunk for each step
4- go to Knit - PDF to save a file as PDF but I got an error
any help please

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] PDF form Rstudio

2016-02-25 Thread Alnazer Elbedairy
these are errors I got

processing file: l...@m.rmd
  | |   6%
  ordinary text without R code

  | |  12%
label: unnamed-chunk-1
  |...  |  18%
  ordinary text without R code

  |...  |  24%
label: unnamed-chunk-2
  |...  |  29%
  ordinary text without R code

  |...  |  35%
label: unnamed-chunk-3
  |...  |  41%
  ordinary text without R code

  |...  |  47%
label: unnamed-chunk-4

Quitting from lines 42-48 (l...@m.rmd)
Error in `$<-.data.frame`(`*tmp*`, "HorsePower", value = numeric(0)) :
  replacement has 0 rows, data has 398
Calls:  ... withVisible -> eval -> eval -> $<- -> $<-.data.frame
Execution halted

No TeX installation detected (TeX is required to create PDF output). You
should install a recommended TeX distribution for your platform:

  Windows: MiKTeX (Complete) - http://miktex.org/2.9/setup
  (NOTE: Be sure to download the Complete rather than Basic installation)

  Mac OS X: TexLive 2013 (Full) - http://tug.org/mactex/
  (NOTE: Download with Safari rather than Chrome _strongly_ recommended)

  Linux: Use system package manager

On Thu, Feb 25, 2016 at 3:58 PM, Erin Hodgess 
wrote:

> What's the error?  You have to show it and the Rmd too, please.
>
>
>
> On Thu, Feb 25, 2016 at 5:35 PM, Alnazer Elbedairy <
> alnazer.elbeda...@gmail.com> wrote:
>
>> Dear All
>> I did the following steps to get a PDF file from Rstudio
>> 1- activate Rmarkdown
>> 2- save file as (name.Rmd)
>> 3- use chunk for each step
>> 4- go to Knit - PDF to save a file as PDF but I got an error
>> any help please
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@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.
>>
>
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] PDF form Rstudio

2016-02-26 Thread Alnazer Elbedairy
installed, but you have to install TEXmaker too, it works now, thank you
guys

On Thu, Feb 25, 2016 at 11:10 PM, Thomas Petzoldt  wrote:

> Yes, you are right. Sweave depends on Latex too, so its no workaround in
> this case.
>
> Hope it helps, thpe
>
> Am 26.02.2016 um 06:54 schrieb Ulrik Stervbo:
>
>> My understanding is that Sweave also depends on LaTeX to generate pdfs, so
>> I am not sure Sweave is the solution.
>>
>>
> Just follow the advice given in the error message:
>
> No TeX installation detected (TeX is required to create PDF output). You
> should install a recommended TeX distribution for your platform:
>
>Windows: MiKTeX (Complete) - http://miktex.org/2.9/setup
>(NOTE: Be sure to download the Complete rather than Basic
>
 installation)

>
>Mac OS X: TexLive 2013 (Full) - http://tug.org/mactex/
>(NOTE: Download with Safari rather than Chrome _strongly_
> recommended)
>
>Linux: Use system package manager
>
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] help in KNN

2016-02-29 Thread Alnazer Elbedairy
dear all
attached you will find a csv datasets, there are many steps before these
they work properly. but I have errors in these steps I guess. any help
appreciated.

Step1: convert the data from continuous to categorical

##nautodata is the normalized data. I did it in the previous steps.

MPGCat= c(0,10,15,20,25,30, 35, 40)
MPG <- cut(nautodata$mydata.MPG, MPGCat,labels = c(1:7))
nautodata = data.frame(MPG, nautodata[2:7])
nautodata


Step 2: divided into 10 folds: as follow


fold1= nautodata[1:39,]
fold2= nautodata[40:79,]
fold3= nautodata[80:119,]
fold4= nautodata[120:159,]
fold5= nautodata[160:199,]
fold6= nautodata[200:139,]
fold7= nautodata[240:279,]
fold8= nautodata[280:319,]
fold9= nautodata[320:359,]
fold10= nautodata[360:398,]

datafolds= list(fold1, fold2, fold3, fold4,
fold5,fold6,fold7,fold8,fold9,fold10)

step3:
##conduct 10-fold cross validation on KNN

KNNFoldError= c(0,0,0,0,0,0,0,0,0,0)
MGFoldError=  c(0,0,0,0,0,0,0,0,0,0)

for (i in 1:10)
{
trainData = NULL
for(j in 1:10)
{
  if(i !=j)
{
 trainData = rbind(trainData, datafolds[[j]])
}
  else
testData = datafolds[[j]]
}
#print (trainData)
#print(testData)
  targetData = trainData$MPG
  testTargetData = testData$MPG

  trainData$MPG= NULL
  testData$MPG = NULL

  M1 = knn(train=trainData, test=testData, cl=targetData, k=20)
  M2 = MajorityGuessing(testData,MPGCat)
  print(table(testTargetData,M1))
  print(testTargetData)
  print(M1)
  print(M2)

  KNNFoldError[i] = round(mean(testTargetData != M1), 3)
  MGFoldError[i] = round(mean(testTargetData != M2), 3)
  print(KNNFoldError)
  print(MGFoldError)
}

## these are the error I got:
Quitting from lines 80-86 (l...@m.rmd)
Error in cut.default(nautodata$mydata.MPG, MPGCat, labels = c(1:7)) :
  'x' must be numeric
Calls:  ... withCallingHandlers -> withVisible -> eval -> eval
-> cut -> cut.default
Execution halted
__
R-help@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.