Ex N0 Implement Naive Bayes models
CLICK HERE >> PROGRAM
Aim
To write a python program to implementation of naive bayes
model using a titanic dataset.
Algorithm
1. Import the required libraries: numpy, pandas, sklearn,
and warnings.
2. Suppress the warnings.
3. Mount Google Drive to access the Titanic dataset in CSV
format.
4. Read the dataset from the CSV file and print the shape of
the dataframe.
5.Convert the 'Sex' column values to
numerical values and print the head of the dataframe.
6. Select the required columns for input features and output
variable.
7. Split the data into training and testing sets.
8. Create a Gaussian Naive Bayes model.
9. Fit the model to the training data.
10. Take input from the user for a person's Pclass
number, gender, age, and fare.
11. Create a list containing the input values.
12. Predict the output for the given input using the fitted
model.
13. Print the prediction as whether the person might survive
or not.
14. Predict the output for the test set.
15. Calculate and print the accuracy score.
Result
Thus the implementation of Naive Bayes model has been
executed successfully.
No comments:
Post a Comment