Crash Detection Model
This model predicts whether a crash is likely based on sensor data (accelerometer and gyroscope values).
Input Features:
- accel_x: Accelerometer data on the x-axis.
- accel_y: Accelerometer data on the y-axis.
- accel_z: Accelerometer data on the z-axis.
- gyro_x: Gyroscope data on the x-axis.
- gyro_y: Gyroscope data on the y-axis.
- gyro_z: Gyroscope data on the z-axis.
- timestamp: Unix timestamp of the data.
Output:
- crash_prediction:
1if a crash is predicted,0otherwise.
Example Request:
To send a POST request to the /predict endpoint with the sensor data, the JSON body should be formatted like this:
{
"accel_x": -1.5,
"accel_y": 8.2,
"accel_z": 0.3,
"gyro_x": 0.15,
"gyro_y": -0.25,
"gyro_z": 0.13,
"timestamp": 1625432933
}
Example Response:
The response will contain a JSON object with the crash prediction:
{
"crash_prediction": 1
}
crash_prediction:1indicates a crash is predicted, and0indicates no crash.
How to Use:
- Send a POST request with the JSON data above to the
/predictendpoint. - Receive a response with the predicted crash status (either
1for a crash or0for no crash).
Model Details:
The model was trained using accelerometer and gyroscope data. It was built with a Random Forest classifier, a reliable model for this type of prediction task. The input features are preprocessed using a StandardScaler to normalize the data.
The model is packaged in a Flask API for easy deployment and integration.
Requirements:
- Python 3.6+
- Flask
- scikit-learn
- pandas
- joblib
To install the necessary dependencies, run:
pip install -r requirements.txt
Example Usage:
- Clone the repository and install the dependencies as shown above.
- Run the Flask app locally by executing:
python app.py
By default, it runs on http://127.0.0.1:5000/.
3. Send a POST request to http://127.0.0.1:5000/predict with the sensor data to get the crash prediction.
Troubleshooting:
- If you encounter issues with dependencies, make sure to use a virtual environment.
- For deployment, ensure your model files (
crash_detection_model.pklandscaler.pkl) are properly included.
This README provides detailed information for using the model API, including how to structure your data for prediction requests and the expected output. It also includes basic setup instructions, dependencies, and usage steps.