Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The file Accidents.csv below contains information on 42,183 actual automobile accidents in 2001 in theUnited States that involved one of three levels of injury: NO

The file

Accidents.csv

below contains information on 42,183 actual automobile accidents in 2001 in theUnited States that involved one of three levels of injury:

NO INJURY

INJURY, or

FATALITY.

For each accident, additional information is recorded, such as day of the week, weather conditions, and road type. A firm might be interested in developing a system for quickly classifying the severity of an accident based on initial reports and associated data in the system (some of which rely on GPS-assisted reporting).

You will use it to practice data mining in R.

Your goal is to predict whether an accident just reported will involve an injury (MAX_SEV_IR = 1 or 2) or will not(MAX_SEV_IR = 0). For this purpose, make a dummy variable called INJURY that takes the value "yes" if MAX_SEV_IR = 1 or 2, and otherwise "no."

1) While looking at only the FIRST 12 records: if an accident has just been reported and no further information is available, what should the prediction be? (INJURY = Yes or No?) Why?

2) Select the first 12 records in the dataset and look only at the response (INJURY) and the two predictors WEATHER_R and TRAF_CON_R. Then:

a) Have a pivot table that examines INJURY as a function of the two predictors for these 12records. Use all three variables in the pivot table as rows/columns.

b) Compute the exact Bayes conditional probabilities of an injury (INJURY = Yes) given the six possible combinations of the predictors.

c) Classify the 12 accidents using these probabilities and a cutoff of 0.5.

d) Compute manually the naive Bayes conditional probability of an injury given WEATHER_R = 1and TRAF_CON_R = 1. Then,

Run a naive Bayes classifier on the 12 records and two predictors using R. Check the model output to obtain probabilities and classifications for all 12 records. Compare this to the exact Bayes classification. Are the resulting classifications equivalent? Is the ranking (= ordering) of observations equivalent?

3) Looking at the WHOLE Dataset:

a) Partition the data into training (60%) and validation (40%)

b) assuming that no information or initial reports about the accident itself are available at the time of prediction (only location characteristics, weather conditions, etc.), which predictors can we include in the analysis? (Use the Data_Codes sheet.)

c) Run a naive Bayes classifier on the complete training set with the relevant predictors (and INJURYas the response). Note that all predictors are categorical. Show the confusion matrix. Then:

What is the overall error for the validation set? What is the percent improvement relative to the naive rule (using the validation set)? Examine the conditional probabilities output.

Why do we get a probability of zero for P(INJURY = No SPD_LIM = 5)?

What is the percent improvement relative to the naive rule (using the validation set)?

Why is it after examining the conditional probabilities output, do we get a probability of zero for(INJURY = No SPD_LIM = 5)?

dataset- https://github.com/MyGitHub2120/AccidentsFull

https://docs.google.com/spreadsheets/d/e/2PACX-1vS24OK0y_FlfqpDmkWS5qFDVo44boEbgRNFSE71HN1dhmmG1u16SD6TfbeeyXxDMJwvQMyk-H_h1gxT/pubhtml

My initial codes are

installed.packages("prob")

installed.packages("tidytable")

installed.packages("naivebayes")

installed.packages("dplyr")

installed.packages("ggplot2")

read.csv(file.choose("AccidentFull"))

accidents.df<-AccidentsFull

inj.tbl<-table(accidents.df$INJURY_CRASH)

prob.inj<-(inj.tbl["yes"])/(inj.tbl["yes"] + inj.tbl["no"])

prob.inj

But it gave me a NA as a result.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Basic College Mathematics (Subscription)

Authors: Elayn Martin Gay

6th Edition

0134844947, 9780134844947

More Books

Students also viewed these Mathematics questions

Question

13. Give four examples of psychological Maginot lines.

Answered: 1 week ago