<jupyter_start><jupyter_text>Encoding non-numeric data to integers<jupyter_code># School (binomial)
le.fit(student_data[:,0])
student_data[:,0] = le.transform(student_data[:,0])
# Sex (binomial)
le.fit(student_data[:,1])
student_data[:,1] = le.transform(student_data[:,1])
# address (binomial)
le.fit(student_data[:,3])
student_data[:,3] = le.transform(student_data[:,3])
# Famsize (binomial)
le.fit(student_data[:,4])
student_data[:,4] = le.transform(student_data[:,4])
# Pstatus (binomial)
le.fit(student_data[:,5])
student_data[:,5] = le.transform(student_data[:,5])
# Mjob (nominal)
le.fit(student_data[:,8])
student_data[:,8] = le.transform(student_data[:,8])
# Fjob (nominal)
le.fit(student_data[:,9])
student_data[:,9] = le.transform(student_data[:,9])
# Reason (nominal)
le.fit(student_data[:,10])
student_data[:,10] = le.transform(student_data[:,10])
# Guardian (nominal)
le.fit(student_data[:,11])
student_data[:,11] = le.transform(student_data[:,11])
# schoolsup (binomial)
le.fit(student_data[:,15])
student_data[:,15] = le.transform(student_data[:,15])
# famsup (binomial)
le.fit(student_data[:,16])
student_data[:,16] = le.transform(student_data[:,16])
# paid (binomial)
le.fit(student_data[:,17])
student_data[:,17] = le.transform(student_data[:,17])
# activities (binomial)
le.fit(student_data[:,18])
student_data[:,18] = le.transform(student_data[:,18])
# nursery (binomial)
le.fit(student_data[:,19])
student_data[:,19] = le.transform(student_data[:,19])
# higher (binomial)
le.fit(student_data[:,20])
student_data[:,20] = le.transform(student_data[:,20])
# internet (binomial)
le.fit(student_data[:,21])
student_data[:,21] = le.transform(student_data[:,21])
# romantic (binomial)
le.fit(student_data[:,22])
student_data[:,22] = le.transform(student_data[:,22])
student_data<jupyter_output><empty_output><jupyter_text>Encoding 0's to -1 for binomial data.  Surely there's a one line method to do this... right, Keras?<jupyter_code>school = student_data[:,0]
school = np.where(school==0, -1, school)
student_data[:,0] = school
sex = student_data[:,1]
sex = np.where(sex==0, -1, sex)
student_data[:,1] = sex
address = student_data[:,3]
address = np.where(address==0, -1, address)
student_data[:,3] = address
famsize = student_data[:,4]
famsize = np.where(famsize==0, -1, famsize)
student_data[:,4] = famsize
Pstatus = student_data[:,5]
Pstatus = np.where(Pstatus==0, -1, Pstatus)
student_data[:,5] = Pstatus
schoolsup = student_data[:,15]
schoolsup = np.where(schoolsup==0, -1, schoolsup)
student_data[:,15] = schoolsup
famsup = student_data[:,16]
famsup = np.where(famsup==0, -1, famsup)
student_data[:,16] = famsup
paid = student_data[:,17]
paid = np.where(paid==0, -1, paid)
student_data[:,17] = paid
activities = student_data[:,18]
activities = np.where(activities==0, -1, activities)
student_data[:,18] = activities
nursery = student_data[:,19]
nursery = np.where(nursery==0, -1, nursery)
student_data[:,19] = nursery
higher = student_data[:,20]
higher = np.where(higher==0, -1, higher)
student_data[:,20] = higher
internet = student_data[:,21]
internet = np.where(internet==0, -1, internet)
student_data[:,21] = internet
romantic = student_data[:,22]
romantic = np.where(romantic==0, -1, romantic)
student_data[:,22] = romantic<jupyter_output><empty_output><jupyter_text>Standardizing the nominal and numerical data.<jupyter_code>scaler = preprocessing.StandardScaler()<jupyter_output><empty_output><jupyter_text>I don't think this warning is THAT concerning<jupyter_code>temp = student_data[:,[2,6,7,8,9,10,11,12,13,14,23,24,25,26,27,28,29]]
Standardized = scaler.fit_transform(temp)<jupyter_output>/nfshome/apps/python-3.6.7/lib/python3.6/site-packages/sklearn/utils/validation.py:590: DataConversionWarning: Data with input dtype object was converted to float64 by StandardScaler.
  warnings.warn(msg, DataConversionWarning)
/nfshome/apps/python-3.6.7/lib/python3.6/site-packages/sklearn/utils/validation.py:590: DataConversionWarning: Data with input dtype object was converted to float64 by StandardScaler.
  warnings.warn(msg, DataConversionWarning)<jupyter_text>Not sure about the -0.0 for the mean...<jupyter_code>print('Mean:', round(Standardized.mean()))
print('Standard deviation:', Standardized.std())
student_data[:,[2,6,7,8,9,10,11,12,13,14,23,24,25,26,27,28,29]] = Standardized
x = student_data[:,0:30]
x[0,0:]
results = student_data[:,32] # output vector<jupyter_output><empty_output><jupyter_text>Convert results to one-hot encoding the actual output vector doesn't include at least one example of each possible grade so I made a vector of all possibilities for to_categorical<jupyter_code>possible_results = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
y = keras.utils.to_categorical(results, len(possible_results))<jupyter_output><empty_output><jupyter_text>Data is now preprocessed  Note: columns 31 and 32 are not used. I do not believe they are useful for our net.<jupyter_code>model = keras.Sequential()
input_size = x.shape[1]
output_size = y.shape[1]
# create the hidden layer
model.add(keras.layers.Dense(400,input_dim=input_size,activation='relu'))
model.add(keras.layers.Dense(200,activation='relu'))
# output layer
model.add(keras.layers.Dense(output_size,activation='softmax'))
# compile
model.compile(loss='categorical_crossentropy',optimizer='adam', metrics=['accuracy'])
model.summary()<jupyter_output>_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_18 (Dense)             (None, 400)               12400     
_________________________________________________________________
dense_19 (Dense)             (None, 200)               80200     
_________________________________________________________________
dense_20 (Dense)             (None, 20)                4020      
=================================================================
Total params: 96,620
Trainable params: 96,620
Non-trainable params: 0
_________________________________________________________________<jupyter_text>Model Training This is some results from training the model Loss seems to be going down slowly Interestingly val_loss seems to be increasing  I have ploted the loss below I could not plot accuracy which is weird and I will have to look into what is causing that Austin<jupyter_code>history = model.fit(x,y,batch_size = 32, epochs = 160, verbose = 0, validation_split = 0.25)
plt.plot(history.history['loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train'], loc='upper left')
plt.show()

score = model.evaluate(x,y, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])<jupyter_output>Test loss: 1.9049611709701997
Test accuracy: 0.7781201849113261
{'fraction_non_alphanumeric': 0.1717557251908397, 'fraction_numerical': 0.05358191426893717, 'mean_word_length': 7.1985559566787005, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '605490', 'license': 'MIT', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2343, 'n_words': 456, 'path': '.ipynb_checkpoints/LSTM-checkpoint.ipynb', 'repo_name': 'CSCI4850/S19-team3-project', 'size': '6812'}