Skip to content
!pip install kaggle
import json
import os
from kaggle.api.kaggle_api_extended import KaggleApi
# Path to where the Kaggle API key is stored
kaggle_json_path = os.path.join(os.path.expanduser('~'), '.kaggle', 'kaggle.json')
# Load the Kaggle API key
with open(kaggle_json_path) as f:
kaggle_api_key = json.load(f)
# Initialize Kaggle API
api = KaggleApi()
# Set Kaggle API credentials directly
api.set_config_value('username', 'rrivas2')
api.set_config_value('key', '0312095f24321eb24b9dce6f85c54b5b')
# Download the dataset
api.dataset_download_files(dataset='outofskills/driving-behavior', unzip=True)
import pandas as pd
train = pd.read_csv('train_motion_data.csv')
train.head()
train.describe()
train.info()
train.shape
import matplotlib.pyplot as plt
# Filtering the dataset for the 'slowdriving' category
slowdriving_data = train[train['Class'] == 'SLOW']
# Plotting acceleration data (AccX, AccY) for the 'slowdriving' category
plt.figure(figsize=(15, 6))
plt.plot(slowdriving_data['Timestamp'], slowdriving_data['AccX'], label='AccX')
plt.plot(slowdriving_data['Timestamp'], slowdriving_data['AccY'], label='AccY')
plt.xlabel('Timestamp')
plt.ylabel('Acceleration')
plt.title('Acceleration Data (AccX, AccY) Over Time for Slow Driving')
plt.legend()
plt.show()
import matplotlib.pyplot as plt
# Filtering the dataset for the 'slowdriving' category
normaldriving_data = train[train['Class'] == 'NORMAL']
# Plotting acceleration data (AccX, AccY) for the 'slowdriving' category
plt.figure(figsize=(15, 6))
plt.plot(normaldriving_data['Timestamp'], normaldriving_data['AccX'], label='AccX')
plt.plot(normaldriving_data['Timestamp'], normaldriving_data['AccY'], label='AccY')
plt.xlabel('Timestamp')
plt.ylabel('Acceleration')
plt.title('Acceleration Data (AccX, AccY) Over Time for Normal Driving')
plt.legend()
plt.show()
import matplotlib.pyplot as plt
# Filtering the dataset for the 'slowdriving' category
aggressivedriving_data = train[train['Class'] == 'AGGRESSIVE']
# Plotting acceleration data (AccX, AccY) for the 'slowdriving' category
plt.figure(figsize=(15, 6))
plt.plot(aggressivedriving_data['Timestamp'], aggressivedriving_data['AccX'], label='AccX')
plt.plot(aggressivedriving_data['Timestamp'], aggressivedriving_data['AccY'], label='AccY')
plt.xlabel('Timestamp')
plt.ylabel('Acceleration')
plt.title('Acceleration Data (AccX, AccY) Over Time for Aggressive Driving')
plt.legend()
plt.show()
import matplotlib.pyplot as plt
# Plotting gyro data (GyroY, GyroZ) for the 'slowdriving' category
plt.figure(figsize=(15, 6))
plt.plot(slowdriving_data['Timestamp'], slowdriving_data['GyroY'], label='GyroY')
plt.plot(slowdriving_data['Timestamp'], slowdriving_data['GyroZ'], label='GyroZ')
plt.xlabel('Timestamp')
plt.ylabel('Gyro readings')
plt.title('Gyro Data (GyroY, GyroZ) Over Time for Slow Driving')
plt.legend()
plt.show()
import matplotlib.pyplot as plt
# Plotting gyro data (GyroY, GyroZ) for the 'normaldriving' category
plt.figure(figsize=(15, 6))
plt.plot(normaldriving_data['Timestamp'], normaldriving_data['GyroY'], label='GyroY')
plt.plot(normaldriving_data['Timestamp'], normaldriving_data['GyroZ'], label='GyroZ')
plt.xlabel('Timestamp')
plt.ylabel('Gyro readings')
plt.title('Gyro Data (GyroY, GyroZ) Over Time for Normal Driving')
plt.legend()
import matplotlib.pyplot as plt
# Plotting gyro data (GyroY, GyroZ) for the 'aggressivedriving' category
plt.figure(figsize=(15, 6))
plt.plot(aggressivedriving_data['Timestamp'], aggressivedriving_data['GyroY'], label='GyroY')
plt.plot(aggressivedriving_data['Timestamp'], aggressivedriving_data['GyroZ'], label='GyroZ')
plt.xlabel('Timestamp')
plt.ylabel('Gyro readings')
plt.title('Gyro Data (GyroY, GyroZ) Over Time for Aggressive Driving')
plt.legend()
plt.show()
# Assume df is your DataFrame containing the dataset
class_mapping = {
'SLOW': 0,
'NORMAL': 1,
'AGGRESSIVE': 2
}
# Add a new column with numerical labels
train['Class_Labels'] = train['Class'].map(class_mapping)
# Print the mapping of original class labels to numerical labels
print("Class Label Mapping:")
for label, numeric_label in class_mapping.items():
print(f"{label}: {numeric_label}")
y_train = train['Class_Labels']
X_train = train.drop(columns=['Class','Class_Labels','Timestamp'])
X_train.head()