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?

Issue hee

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

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.)

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 native 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/Accidentsdataset

Issue hee

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

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.)

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:

Here are my codes

spec = c(train = .6, validate = .4)

df=data.frame(ALIGN_I, WRK_ZONE, WKDY_I_R, INT_HWY, LGTCON_I_R, PROFIL_I_R, SPD_LIM, SUR_CON, TRAF_CON_R,

TRAF_WAY, WEATHER_R)

df=data.frame(accidents.df)

g = sample(cut(

seq(nrow(df)),

nrow(df)*cumsum(c(0,spec)),

labels = names(spec)

))

res=split(df,g)

train=res$train

validate=res$validate

Error message- Error in data.frame(ALIGN_I, WRK_ZONE, WKDY_I_R, INT_HWY, LGTCON_I_R,:

object 'ALIGN_I' not found why?

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_2

Step: 3

blur-text-image_3

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

Ordinary Differential Equations

Authors: William A Adkins, Mark G Davidson

1st Edition

1461436184, 9781461436188

More Books

Students also viewed these Mathematics questions

Question

250 2 ft 4ft * 2 ft 500 lb

Answered: 1 week ago

Question

3. How can we use information and communication to generate trust?

Answered: 1 week ago