#------------------------------------------------------------------------------- # Part 1 - Perceptron Algorithm #------------------------------------------------------------------------------- # toy_features, toy_labels = utils.load_toy_data('../../Data/toy_data.csv') # # theta, theta_0 = lab2.perceptron(toy_features, toy_labels, T=5) # # utils.plot_toy_results(toy_features, toy_labels, theta, theta_0) #------------------------------------------------------------------------------- # Part 2 - Classifying Reviews #------------------------------------------------------------------------------- theta, theta_0 = lab2.perceptron(train_bow_features, train_labels, T=5) train_accuracy = lab2.accuracy(train_bow_features, train_labels, theta, theta_0) val_accuracy = lab2.accuracy(val_bow_features, val_labels, theta, theta_0) # # print("Training accuracy: {:.4f}".format(train_accuracy)) # print("Validation accuracy: {:.4f}".format(val_accuracy)) #------------------------------------------------------------------------------- # Part 3 - Improving the Model #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- # Part 3.1 - Tuning the Hyperparameters #-------------------------------------------------------------------------------
bigram_dictionary = lab2.bigram_dictionary(train_texts) train_final_features = lab2.extract_final_features(train_texts, dictionary, bigram_dictionary) val_final_features = lab2.extract_final_features(val_texts, dictionary, bigram_dictionary) test_final_features = lab2.extract_final_features(test_texts, dictionary, bigram_dictionary) #------------------------------------------------------------------------------- # Part 1 - Perceptron Algorithm #------------------------------------------------------------------------------- toy_features, toy_labels = utils.load_toy_data('../../Data/toy_data.csv') theta, theta_0 = lab2.perceptron(toy_features, toy_labels, T=5) utils.plot_toy_results(toy_features, toy_labels, theta, theta_0) #------------------------------------------------------------------------------- # Part 2 - Classifying Reviews #------------------------------------------------------------------------------- theta, theta_0 = lab2.perceptron(train_bow_features, train_labels, T=5) train_accuracy = lab2.accuracy(train_bow_features, train_labels, theta, theta_0) val_accuracy = lab2.accuracy(val_bow_features, val_labels, theta, theta_0) print("Training accuracy: {:.4f}".format(train_accuracy)) # 0.9850 print("Validation accuracy: {:.4f}".format(val_accuracy)) # 0.8943
val_bow_features = lab2.extract_bow_feature_vectors(val_texts, dictionary) test_bow_features = lab2.extract_bow_feature_vectors(test_texts, dictionary) # You may modify the following when adding additional features (Part 3c) train_final_features = lab2.extract_final_features(train_texts, dictionary) val_final_features = lab2.extract_final_features(val_texts, dictionary) test_final_features = lab2.extract_final_features(test_texts, dictionary) #------------------------------------------------------------------------------- # Part 1 - Perceptron Algorithm #------------------------------------------------------------------------------- toy_features, toy_labels = utils.load_toy_data('../../Data/toy_data.csv') theta, theta_0 = lab2.perceptron(toy_features, toy_labels, T=5) utils.plot_toy_results(toy_features, toy_labels, theta, theta_0) #------------------------------------------------------------------------------- # Part 2 - Classifying Reviews #------------------------------------------------------------------------------- #theta,theta_0 = lab2.perceptron(train_bow_features, train_labels, T=5) #train_accuracy = lab2.accuracy(train_bow_features, train_labels, theta, theta_0) #val_accuracy = lab2.accuracy(val_bow_features, val_labels, theta, theta_0) #print("Training accuracy: {:.4f}".format(train_accuracy)) #print("Validation accuracy: {:.4f}".format(val_accuracy))