def dataWrapper(): dataSet = splitData(df = omitOutliers()) trainSet = dataSet['trainSet'] testSet = dataSet['testSet'] trainSetX = trainSet.loc[:,'mcg':'nuc'] trainSetClass = trainSet['Class'] testSetX = testSet.loc[:,'mcg':'nuc'] testSetClass = testSet['Class'] return {'trainX':trainSetX, 'trainClass':trainSetClass,'testX':testSetX,'testClass':testSetClass}
def setData(): data = loadData() dataSet = splitData(data) trainSet = dataSet['trainSet'] testSet = dataSet['testSet'] xtrain = np.array(trainSet.loc[:,'mcg':'nuc']) ytrain = np.array(trainSet['Class']) ytrain = np.array(pd.get_dummies(ytrain)) #print(ytrain) #print(len(ytrain[0])) xtest = np.array(testSet.loc[:,'mcg':'nuc']) ytest = np.array(testSet['Class']) ytest = np.array(pd.get_dummies(ytest)) activation_1 = layers.Dense(units=3, activation='sigmoid') #First layer activation_2 = layers.Dense(units=3, activation='sigmoid') #Second layer output_layer = layers.Dense(units=10,activation='softmax') #Output layer #To build up the model model = Sequential([activation_1,activation_2,output_layer]) #initialized the model sgd = optimizers.SGD(lr=0.1) model.compile(loss='categorical_crossentropy',optimizer=sgd,metrics=['accuracy']) weight_receive= [] print_weights = LambdaCallback(on_epoch_end=lambda batch, logs: ([weight_receive.append(output_layer.get_weights())]).append(activation_2.get_weights())) history = model.fit(xtrain, ytrain, epochs=50,batch_size=1,verbose=0,callbacks = [print_weights]) error = [] for i in range(len(history.history['acc'])): error.append(1-(history.history['acc'][i])) output_weight = output_layer.get_weights() layer2 = activation_2.get_weights() print('Training error:',error[len(error)-1]) print('Outputlayer all weights:','\n',output_weight[0]) print('Outputlayer bias:','\n',output_weight[1]) print('Second Hidden layer all weights:','\n',layer2[0]) print('Second Hidden layer bias:','\n',layer2[1])
plt.xlim(0,4) plt.ylim(0,10) outtemp = avrage_data(data,run_or_walk) xa, moving_avg, min_sigma, max_sigma = outtemp['frequency'], outtemp['avg'], outtemp['min sigma'], outtemp['max sigma'] plt.fill_between(xa['frequency'],min_sigma,max_sigma,alpha=0.4) plt.plot(xa['frequency'],moving_avg,'r') #plt.plot(x['frequency'], x['magnitude']) def median(lst): return np.median(np.array(lst)) def mean(lst): return sum(lst)/len(lst) if __name__ == '__main__': data = splitData() plt.rc('text', usetex=True) plt.rc('font', family='serif') fig = plt.figure(figsize=(8,13), tight_layout=True) # ax = list() # ax.append() afrequesy_plot(data,'walk',(4,1,1)) afrequesy_plot(data,'run',(4,1,2)) movingmedian_plot(data,'walk',(4,1,3)) movingmedian_plot(data,'run',(4,1,4)) plt.subplots_adjust(hspace=0.53) plt.savefig('plot.png') plt.show()