(Solved) : Using R Programming Language Observations 32 561variables 16 Age 39 50 38 53 28 37 49 52 3 Q42766303 . . .

I am using R programming language

Observations: 32,561Variables: 16$ age <int> 39, 50, 38, 53, 28, 37, 49, 52, 31, 42, 37, 30, 23…$ workclass <fct> State-gov, Self-emp-not-inc, Private, Private,…$ fnlwgt <int> 77516, 83311, 215646, 234721, 338409, 284582, 1601…$ education <fct> Bachelors, Bachelors, HS-grad, 11th, Bachelor…$ education.num <int> 13, 13, 9, 7, 13, 14, 5, 9, 14, 13, 10, 13, 13, 12…$ marital.status <fct> Never-married, Married-civ-spouse, Divorced, M…$ occupation <fct> Adm-clerical, Exec-managerial, Handlers-cleaner…$ relationship <fct> Not-in-family, Husband, Not-in-family, Husband…$ race <fct> White, White, White, Black, Black, White, B…$ sex <fct> Male, Male, Male, Male, Female, Female, Fem…$ capital.gain <int> 2174, 0, 0, 0, 0, 0, 0, 0, 14084, 5178, 0, 0, 0, 0…$ capital.loss <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…$ hours.per.week <int> 40, 13, 40, 40, 40, 40, 16, 45, 50, 40, 80, 40, 30…$ native.country <fct> United-States, United-States, United-States, U…$ income <fct> <=50K, <=50K, <=50K, <=50K, <=50K, <=50K, <…$ income_ind <dbl> 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0,…income <=50K >50K 75.82485 24.17515

Use `KNN` algorithm to classify the earners (`<=50K,>50K`, low/high) for High-earners in the 1994 United StatesCensus data above. Select only the quantitative variables`age,education.num, capital.gain, capital.loss, hours.per.week`.Use `cl=train$income` and `k=1`(use the closest neighbor) in the`knn` argumnts. Print the confusion matrix. State the accuracy.

YOUR ANSWER HERE

“`{r} library(class)

# create training set only for select variables. Notice dplyr::before select. It is used to avoid conflict with

train_q <- train %>% dplyr::select(age,education.num,capital.gain, capital.loss, hours.per.week)

1. define knn classfier

2. look at the confusion matrix for the test set

3. print the confusion matrix

4. find the Accuracy = (true positive and truenegative)/total

“`

Expert Answer


Answer to I am using R programming language Observations: 32,561 Variables: 16 $ age 39, 50, 38, 53, 28, 37, 49, 52, 31, 42, 37, 3…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?