Exemplo n.º 1
0
def t_predict(features, labels, cameras):

    log_file = '/driving_log.csv'
    log_path = './data'
    skiprows = 1
    # load the csv log file
    print("Camera: ", cameras)
    print("Log path: ", log_path)
    print("Log file: ", log_file)

    column_names = [
        'center', 'left', 'right', 'steering', 'throttle', 'brake', 'speed'
    ]
    data_df = pd.read_csv(log_path + '/' + log_file,
                          names=column_names,
                          skiprows=skiprows)
    data_count = len(data_df)

    # initialise data extract
    t_features = []
    t_labels = []

    row = data_df.iloc[np.random.randint(data_count - 1)]
    steering = getattr(row, 'steering')
    image = load_image(log_path, getattr(row, cameras[0]))

    t_features.append(image)
    t_labels.append(steering)

    clf = GaussianNB()
    clf.fit(features, labels)
    pred = clf.pred(t_features)
    print(accuracy_score(pred, t_labels))
### labels_train and labels_test are the corresponding item labels
features_train, features_test, labels_train, labels_test = preprocess()




#########################################################
### your code goes here ###

# Defining Classifier - Gaussian Naive Bayes
clf = GaussianNB()

# Fitting the training data set
# training the test data set labels
t0 = time()
clf.fit(features_train,lables_train)
print("training naive bayes:", round(time()-t0, 3), "s")

#predicting the test dataset labels using the trained statistics
t0 = time()
pred = clf.pred(features_test)
print("predicting naive bayes:", round(time()-t0, 3), "s")


accuracy = clf.score(features_test,labels_test)
print(accuracy)

#########################################################