import numpy as np
import pandas as pd

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, classification_report

"""
Explanation: Stay Alert! The Ford Challenge
by Scott Josephson
Driving while distracted, fatigued or drowsy may lead to accidents. Activities that divert the driver's attention from the road ahead, such as engaging in a conversation with other passengers in the car, making or receiving phone calls, sending or receiving text messages, eating while driving or events outside the car may cause driver distraction. Fatigue and drowsiness can result from driving long hours or from lack of sleep.
The data for this Kaggle challenge shows the results of a number of "trials", each one representing about 2 minutes of sequential data that are recorded every 100 ms during a driving session on the road or in a driving simulator.  The trials are samples from some 100 drivers of both genders, and of different ages and ethnic backgrounds. The files are structured as follows:
The first column is the Trial ID - each period of around 2 minutes of sequential data has a unique trial ID. For instance, the first 1210 observations represent sequential observations every 100ms, and therefore all have the same trial ID
 The second column is the observation number - this is a sequentially increasing number within one trial ID 
The third column has a value X for each row where
           X = 1     if the driver is alert

           X = 0     if the driver is not alert

The next 8 columns with headers P1, P2 , …….., P8  represent physiological data;
The next 11 columns with headers E1, E2, …….., E11  represent environmental data;
The next 11 columns with headers V1, V2, …….., V11  represent vehicular data;
Import Libraries
End of explanation
"""


ford_train = pd.read_csv('fordtrain.csv')

"""
Explanation: Get the Data
Read in the fordtrain.csv file and set it to a data frame called ford_train.
 Split the data into training set and testing set using train_test_split
End of explanation
"""


ford_train.head()

ford_train.info()

"""
Explanation: Check the head of ad_data
End of explanation
"""


X_train, X_test, y_train, y_test = train_test_split(ford_train.drop('IsAlert',axis=1),ford_train['IsAlert'],
                                                    test_size=0.30,random_state=101)

"""
Explanation: Logistic Regression
Now it's time to do a train test split, and train our model!
Choose columns that you want to train on!
End of explanation
"""


logmodel = LogisticRegression()

logmodel.fit(X_train, y_train)

"""
Explanation: Train and fit a logistic regression model on the training set.
End of explanation
"""


predictions = logmodel.predict(X_test)

"""
Explanation: Predictions and Evaluations
 Now predict values for the testing data.
End of explanation
"""


print(classification_report(y_test,predictions))

"""
Explanation: Create a classification report for the model.
End of explanation
"""


