<jupyter_start><jupyter_text><NAME>, 10-6-20201. I import all the libraries I may need and the data set given in the project prompt.2. I set the index of the data set to choral_ID3. I drop event_number (as instructed) and then one hot encode the bass column so that it can be used in the classifer. 4. I use a loop with a lambda statment to convert the "YES" and "NO" to 1 and 0.5. Then, I create the classifer. I went through several different ones trying to find the most efficent one, (specifically a nearest neighbor, elastic, random tree, and linear classifer) and then kept the most effective one which was the decision tree.6. I then split the data into test and train values and fitted the train values to the classifer.7. Then, I tested the classifier. I did both the cross value and standard prediction method to find the accuracy of the classifier. 8. I then created a dataframe that compared the predictions to the actual chord. 9. I adjusted the classifer to be as exact as possible by changing the max_depth and toying with the splitter.The code is commented out as well!<jupyter_code>#import everything
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn import tree

#do not use choral_ID or event_number for training/testing
chords = pd.read_csv("https://raw.githubusercontent.com/zacharski/ml-class/master/data/bach.zip")
chords.set_index('choral_ID', inplace=True)#set the dataframe index
chords
chords = chords.drop("event_number", axis = 1) #remove event_number because it is not relevant
one_hot = pd.get_dummies(chords['bass'], prefix=["bass"]) #one hot encode bass with a prefix to not cause confusion
chords = chords.drop('bass', axis=1) #drop the originial bass column
chords = chords.join(one_hot) #add the encoded bass column

noteArray = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] #create a list of notes
for i in noteArray: #loop through that list to alter the YES and NO into 1 and 0
  chords[i] = chords[i].apply(lambda x: 1 if x == 'YES' else 0)
chords
#chords_train, chords_test = train_test_split(chords, test_size = 0.2)
#chords_trainLabel = chords_train['chord_label']
#chords_trainFeatures = chords_train.drop('chord_label', axis=1)
#chords_testLabel = chords_test['chord_label']
#chords_testFeatures = chords_test.drop('chord_label', axis=1)

dtc = tree.DecisionTreeClassifier(criterion='entropy', max_depth=30) #made the classifer, (I made several different ones but chose this one as most effective)

chords_Features = chords.drop('chord_label', axis = 1) #created a features list by removing the chord_label
chords_Label = chords['chord_label'] #created labels list for the prediction of the labels
chords_trainFeatures, chords_testFeatures, chords_trainLabel, chords_testLabel = train_test_split(chords_Features, chords_Label, test_size = 0.2, random_state=42)
#above, I split the data into train and test
dtc.fit(chords_trainFeatures, chords_trainLabel)#fit the data
scores = cross_val_score(dtc, chords_testFeatures, chords_testLabel, cv=10) #did cross value scoring, I tried different numbers for it but couldnt get a better outcome
print(scores)
print("The average CROSS VALUE accuracy is %5.2f" % (scores.mean())) #found the average cross value accuracy
from sklearn.metrics import accuracy_score
dtc.fit(chords_trainFeatures, chords_trainLabel) #fit the data again to see if it would improve accuracy
chords_predictions = dtc.predict(chords_testFeatures) #used predict to find the chord label predictions
print(chords_predictions)
accuracy = accuracy_score(chords_testLabel, chords_predictions, normalize=True) #found the accuracy of that prediction
print("The accuracy is %5.2f" % accuracy)
comparison = pd.DataFrame(chords_testLabel) #created a dataframe for the comparison
comparison['prediction'] = chords_predictions #added the prediction results
comparison<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0820253164556962, 'fraction_numerical': 0.010379746835443038, 'mean_word_length': 5.919439579684764, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '639927', 'license': 'Apache-2.0', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1171, 'n_words': 481, 'path': "projects/Sally's_Bach_Project.ipynb", 'repo_name': 'sburkley/CS-419', 'size': '3957'}