Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to create Bayesian network in R and inference. I am not sure if my bayesian network is correct or wrong. But somehow

I am trying to create Bayesian network in R and inference. I am not sure if my bayesian network is correct or wrong. But somehow it does not look good. I am sharing my code here. please create a inference now. # Load necessary libraries
library(readr)
library(bnlearn)
library(gRain)
library(ggplot2)
library(reshape2)
library(forcats)
library(dplyr)
# Load data
data <- read.csv("F:/2nd Semester/Data Processing/Bayesian/Dataset/archive (2)/cleaned.csv")
# Convert all columns to factors
data <- lapply(data, as.factor)
data <- data.frame(data)
# levels for specific columns
levels_vehiclemovement = c("Enteringajunction", "Getting off", "Going straight",
"Moving Backward","Other","Overtaking","Parked","Reversing",
"Stopping","Turnover","U-Turn","Unknown","Waiting to go")
levels(data$Vehicle_movement)= levels_vehiclemovement
levels_causeofaccident = c("ChangeLane", "ChangeLane", "DriveHighOrCareless",
"DriveHighOrCareless", "DriveLeft", "DriveAlcohol",
"DriveAlcohol", "Other", "Other","MovingBackward",
"NoDistance", "NoPriority","NoPriority", "Other","Other",
"Other","Other","Other","Other","Other")
levels(data$Cause_of_accident)=levels_causeofaccident
levels_Education = c("AboveHighSchool","ElementarySchool","HighSchool","Other",
"JuniorHighSchool","Unknown", "Other")
levels(data$Education)= levels_Education
levels_drivingexperience =c("1-2yr","2-5yr","5-10yr","Above 10yr","Below1yr","NoLicence",
"Unknown","Unknown")
levels(data$Driving_experience)=levels_drivingexperience
levels_lanes= c("DoubleCarriageway(median)","OneWay","other","Twoway(divided with broken lines road marking)",
"TwoWay(divided with solid lines road marking)","UndividedTwoWay","Unknown")
levels(data$Lanes_or_Medians)=levels_lanes
levels_lightconditions = c("Darknesslightslit","Darknesslightsunlit",
"lightsUnlitDarkness","NoLighting","NoLighting")
levels(data$Light_conditions)=levels_lightconditions
levels_roadSurface = c("AsphaltRoads","AsphaltsRoadswithSomeDistress","EarthRoads",
"GravelRoads","Other","Unknown")
levels(data$Road_surface_type)=levels_roadSurface
levels_weatherconditions = c("Cloudy","FogOrMist","Normal","Other","Raining",
"RainingAndWindy","Snow","Unknown","Windy")
levels(data$Weather_conditions)=levels_weatherconditions
levels_collision = c("CollisionWithAnimals","CollisionWithPedestrians",
"CollisionWithRoadSideParkedVehicle",
"CollisionWithRoadsideObjects","FallFromVehicles","Other","RollOver","Unknown","VehicleWithVehicleCollision","WithTrain")
levels(data$Type_of_collision)=levels_collision
str(data)
summary(data)
bn_structure <- hc(data)
plot(bn_structure)
mmhc
h2pc(data)
network = hc(data)
graphviz.plot(network,shape = "rectangle")

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

How does this scenario illustrate the process of mainstreaming?

Answered: 1 week ago

Question

What are personal and social media?

Answered: 1 week ago