<jupyter_start><jupyter_text>Case Study Objective:• Practice Naive Bayes algorithm based classification.• Identify the predictors that can be of influence by experiment.Questions:1.Load the kinematics dataset as measured on mobile sensors from the file “run_or_walk.csv”. List out the columns in the dataset.2.Let the target variable ‘y’ be the activity and assign all the columns after it to ‘x’.3.Using Scikit-learn fit a Gaussian Naive Bayes model and observe the accuracy. Generate a classification report using scikit learn.4.Repeat the model once using only the acceleration values as predictors and then using only the gyro values as predictors. Comment on the difference in accuracy between both the models.<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('run_or_walk.csv')
df.describe()
df.sample(5)
df.columns
sns.countplot(df.activity)
sns.heatmap(df.corr(),annot=True)
df.drop(['date','time','username'], inplace= True, axis =1)
df.sample(10)
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.naive_bayes import GaussianNB
X = df.drop('activity', axis =1)
y = df.activity
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.3, random_state = 5) 
naivebayes = GaussianNB()
naivebayes.fit(X_train, y_train)
prediction = naivebayes.predict(X_test)
accuracy_score(y_test,prediction)
dfcompare = pd.DataFrame({"Actual":y_test, "Prediction":prediction})
dfcompare.sample(10)
sns.countplot(prediction)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08816120906801007, 'fraction_numerical': 0.008816120906801008, 'mean_word_length': 6.425233644859813, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '187906', 'license': 'MIT', 'n_tokens_mistral': 512, 'n_tokens_neox': 489, 'n_words': 167, 'path': 'Cls6-Supervised Learning - II/.ipynb_checkpoints/SupervisedLearning-II-Casestudy-2-solution-checkpoint.ipynb', 'repo_name': 'tuhinssam/MLResources', 'size': '1588'}