daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from keras.layers import Input, Embedding, LSTM, Dense
  2. from keras.models import Model
  3. import csv
  4. import keras
  5. import pandas as pd
  6. import numpy as np
  7. from keras.constraints import nonneg
  8.  
  9. notes = pd.read_csv('notes.csv',sep=';',encoding='utf-8')
  10. compare = pd.read_csv('compare.csv',sep=';',encoding='utf-8')
  11. len(compare),len(notes)
  12.  
  13. meilleur = list(compare.BEST_ETU)
  14.  
  15. best = pd.DataFrame(columns=['ID_ETU','MATHS','ECO','INFO','ANGLAIS'])
  16. for elt in meilleur:
  17.     best = best.append(notes.iloc[elt:elt+1,:])
  18.  
  19. moins_bon = []
  20. for i in range(len(compare)):
  21.     if compare.ID_ETU1[i] != compare.BEST_ETU[i]:
  22.         moins_bon.append(compare.ID_ETU1[i])
  23.     else :
  24.         moins_bon.append(compare.ID_ETU2[i])
  25.  
  26. worst = pd.DataFrame(columns=['ID_ETU','MATHS','ECO','INFO','ANGLAIS'])
  27. for elt in moins_bon:
  28.     worst = worst.append(notes.iloc[elt:elt+1,:])
  29.  
  30. best = best.drop(columns='ID_ETU')
  31. worst = worst.drop(columns='ID_ETU')
  32.  
  33. best = best.as_matrix()
  34. worst = worst.as_matrix()
  35.  
  36. labels = np.array(1).repeat(len(compare))
  37.  
  38. best.values
  39.  
  40. labels
  41.  
  42. input1 = Input(shape=(4,), dtype='float32', name='input1')
  43. input2 = Input(shape=(4,), dtype='float32', name='input2')
  44.  
  45. dense = Dense(1, activation='linear', W_constraint= nonneg(), bias=False)
  46. dense1 = dense(input1)
  47. dense2 = dense(input2)
  48.  
  49. merged_vector = keras.layers.concatenate([dense1, dense2], axis=-1)
  50.  
  51. predictions = Dense(1, activation='sigmoid')(merged_vector)
  52.  
  53. # We define a trainable model linking the
  54. # tweet inputs to the predictions
  55. model = Model(inputs=[input1,input2], outputs=predictions)
  56.  
  57. model.compile(optimizer='sgd',
  58.               loss='binary_crossentropy',
  59.               metrics=['accuracy'])
  60.  
  61. model.fit([best, worst], labels, epochs=20)
  62.  
  63. poids = list(dense.get_weights())
  64.  
  65. print(poids/np.sum(poids))
  66.  
  67. premier  = [0.2943,0.1542,0.1197,0.4316]
  68. deuxième = [0.0672,0.5911,0.06136159,0.2802]
  69. troisieme = [0.3024,0.0953,0.5506,0.0515]
  70.  
  71. # 4928 vs 7791 --> 7791
  72. #moyenne_4928_1 = 11.861*0.2943 + 13.40322*0.1542 + 11.6018*0.1197 + 8.09329*0.4316
  73. moyenne_4928_2 = 11.861*0.0672 + 13.40322*0.5911 + 11.6018*0.0613 + 8.09329*0.2802
  74. moyenne_7791_1 = 12.525*0.2943 + 14.2538*0.1542 + 12.1152*0.1197 + 8.81223*0.4316
  75. moyenne_7791_2 = 12.525*0.0672 + 14.2538*0.5911 + 12.1152*0.0613 + 8.81223*0.2802
  76.  
  77. print(moyenne_4928_2,moyenne_7791_2)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top