Question

In: Computer Science

I have dataset to predict how pass or fail based on score column. If the grade...

I have dataset to predict how pass or fail based on score column. If the grade is higher than 90 we predict it pass if it below we predict it fall. the class column is the actual result so based on our prediction we got 10 correct answer out of 14. I want to do this I RStudio. To show how many corrected result we got based on the class.

Score Our_prediction class
77.29597 Fail Fail
77.20041 Fail Fail
76.67481 Fail Fail
76.60455 Fail Pass
76.2072 Fail Fail
76.2072 Fail Fail
76.15788 Fail Pass
76.07912 Fail Fail
76.04913 Fail Pass
75.45997 Fail Pass
98.42474 Pass Pass
98.27169 Pass Pass
97.90262 Pass Pass
97.5566 Pass Pass

Solutions

Expert Solution

ANSWER:

  • I have provided the properly commented code in both text and image format so you can easily copy the code as well as check for correct indentation.
  • I have provided the output image of the code so you can easily cross-check for the correct output of the code.
  • Have a nice and healthy day!!

CODE TEXT

# creating score and class data using dataframe
# with score and respective class list
# storing dataframe in data
data <- data.frame(Score=c(77.29597,77.20041,76.67481,76.60455       ,76.2072,76.2072,76.15788       ,76.07912,
                   76.04913,75.45997,98.42474,98.27169,97.90262,97.5566),
           class=c("Fail","Fail","Fail","Pass","Fail","Fail","Pass","Fail","Pass","Pass","Pass",
                   "Pass","Pass","Pass"))

# displaying data
print("Data:")
data

# creating prediction function, to predict pass if Score > 90
predict <- function (X){
  # if X>90 return Pass
  if(X>90){
    "Pass"
  } # else fail
  else
    "Fail"
}

# using function lapply to apply predict function on each Score of data and storing result in Our_prediction
# col of dataframe
data$Our_prediction <- lapply(data$Score, predict)
# displaying prediction data
print("Predicted data in Our_prediction col:")
data

# comparing prediction with actual and displaying result
# comparision will give boolean vector with true where prediction matches, using sum function to fetch
# to correct predictions
correct_pred <- sum(data$Our_prediction == data$class)

# displaying result
cat("Out of",length(data$Our_prediction),", we got",correct_pred,"correct answer.")

CODE IMAGE

OUTPUT IMAGE


Related Solutions

how to find the first, second, third quantile of a column in a dataset with R?...
how to find the first, second, third quantile of a column in a dataset with R? the dataset is like this: columns values a. 1. 2. 3. 5. 6. 7. 4. 7. 8. ......... b 5. 6. 7. 3. 8. 0. 4. 7. 4. 7. ......... c    1. 2. 3. 5. 6. 7. 4. 7. 8. ......... d 6. 3. 1. 0. 8. 3. 6. 6. 3.........
I have conducted a linear regression model to predict student scores on an exam based on...
I have conducted a linear regression model to predict student scores on an exam based on the number of hours they studied. I get a coefficient (slope) of +2.5 for the variable of hours studied. The pvalue for this coefficient is 0.45 and the 95% confidence interval is [-2.5, +7]. Which of the following conclusions CANNOT be drawn from these results? At an alpha of 0.05, we can say that the effect of hours studied on exam score is significant...
4. I have reviewed the midterm grades, and I am trying to predict how well the...
4. I have reviewed the midterm grades, and I am trying to predict how well the class will do on the final exam. The frequency values are actual grades for the Summer II midterm: Grade Expected Frequency (Observed) Greater than A 5 7 A 6 9 B 8 4 C 3 4 D 1 0 F 2 1 a. What will be my degrees of freedom? b. What is O-E (difference) for grades of B? c. What is O-E^2 for...
4. I have reviewed the midterm grades, and I am trying to predict how well the...
4. I have reviewed the midterm grades, and I am trying to predict how well the class will do on the final exam. The frequency values are actual grades for the Summer II midterm: Grade Expected Frequency (Observed) Greater than A 5 7 A 6 9 B 8 4 C 3 4 D 1 0 F 2 1 a. What will be my degrees of freedom? b. What is O-E (difference) for grades of B? c. What is O-E^2 for...
In the United States, first grade kids have an average friendliness score (FS) of 24 with...
In the United States, first grade kids have an average friendliness score (FS) of 24 with a standard deviation of 4. Also these first grade classes all have 23 students in them. Use this information to answer questions #26-#29. What percent of classrooms have FS averages between 23.28 and 23.77? What is the percentile rank of a child with FS equal to 22.88? What percent of classrooms have FS averages less than 26? What percent of classrooms have average friendliness...
1. Why did economists fail to predict and explain the Great Depression? 2. How the Great...
1. Why did economists fail to predict and explain the Great Depression? 2. How the Great Depression shaped the economic theory
How do I pass the University of Indiana plagiarism test??
How do I pass the University of Indiana plagiarism test??
Just Need to see how the dataset and the output will Look in SPSS for I...
Just Need to see how the dataset and the output will Look in SPSS for I can check my answer. Please use SPSS... I need the answer ASAP.. Thanks. Only SPSS Chi-Square Test of Independence satisfied Freshmen Sophomore Junior Senior Yes 21 19 10 20 No 14 9 17 11
how do we interpret how typical a score is compare to the population based on the...
how do we interpret how typical a score is compare to the population based on the population mean and standard deviation
I have a small business based on wholsale. How can I know how much my business...
I have a small business based on wholsale. How can I know how much my business is worth or if it has any stock value??? Is there a website/number I can go to where I see if I even have any stocks??? Because I don’t know how the stock market works (I’m new at this)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT