Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.layers import Input, Embedding, LSTM, Dense
- from keras.models import Model
- import csv
- import keras
- import pandas as pd
- import numpy as np
- from keras.constraints import nonneg
- notes = pd.read_csv('notes.csv',sep=';',encoding='utf-8')
- compare = pd.read_csv('compare.csv',sep=';',encoding='utf-8')
- len(compare),len(notes)
- meilleur = list(compare.BEST_ETU)
- best = pd.DataFrame(columns=['ID_ETU','MATHS','ECO','INFO','ANGLAIS'])
- for elt in meilleur:
- best = best.append(notes.iloc[elt:elt+1,:])
- moins_bon = []
- for i in range(len(compare)):
- if compare.ID_ETU1[i] != compare.BEST_ETU[i]:
- moins_bon.append(compare.ID_ETU1[i])
- else :
- moins_bon.append(compare.ID_ETU2[i])
- worst = pd.DataFrame(columns=['ID_ETU','MATHS','ECO','INFO','ANGLAIS'])
- for elt in moins_bon:
- worst = worst.append(notes.iloc[elt:elt+1,:])
- best = best.drop(columns='ID_ETU')
- worst = worst.drop(columns='ID_ETU')
- best = best.as_matrix()
- worst = worst.as_matrix()
- labels = np.array(1).repeat(len(compare))
- best.values
- labels
- input1 = Input(shape=(4,), dtype='float32', name='input1')
- input2 = Input(shape=(4,), dtype='float32', name='input2')
- dense = Dense(1, activation='linear', W_constraint= nonneg(), bias=False)
- dense1 = dense(input1)
- dense2 = dense(input2)
- merged_vector = keras.layers.concatenate([dense1, dense2], axis=-1)
- predictions = Dense(1, activation='sigmoid')(merged_vector)
- # We define a trainable model linking the
- # tweet inputs to the predictions
- model = Model(inputs=[input1,input2], outputs=predictions)
- model.compile(optimizer='sgd',
- loss='binary_crossentropy',
- metrics=['accuracy'])
- model.fit([best, worst], labels, epochs=20)
- poids = list(dense.get_weights())
- print(poids/np.sum(poids))
- premier = [0.2943,0.1542,0.1197,0.4316]
- deuxième = [0.0672,0.5911,0.06136159,0.2802]
- troisieme = [0.3024,0.0953,0.5506,0.0515]
- # 4928 vs 7791 --> 7791
- #moyenne_4928_1 = 11.861*0.2943 + 13.40322*0.1542 + 11.6018*0.1197 + 8.09329*0.4316
- moyenne_4928_2 = 11.861*0.0672 + 13.40322*0.5911 + 11.6018*0.0613 + 8.09329*0.2802
- moyenne_7791_1 = 12.525*0.2943 + 14.2538*0.1542 + 12.1152*0.1197 + 8.81223*0.4316
- moyenne_7791_2 = 12.525*0.0672 + 14.2538*0.5911 + 12.1152*0.0613 + 8.81223*0.2802
- print(moyenne_4928_2,moyenne_7791_2)
Add Comment
Please, Sign In to add comment