daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ####### What if ########
  2.  
  3. from keras.models import Sequential
  4. from keras.layers import Dense
  5. from keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor
  6. from sklearn.model_selection import StratifiedKFold, KFold
  7. from sklearn.model_selection import cross_val_score
  8. import numpy
  9. from keras import regularizers
  10.  
  11. # KFold vs StratifiedKFold
  12. #One can be a victim of skewed target values with Random subsampling and K-fold which can be fixed by
  13. #stratification. Stratification makes sure that you get similar target distribution in each of your folds
  14. #(chunks) of your data.
  15. # Cross validation allows us to compare different ML algorithm.
  16.  
  17. # Function to create model, required for KerasClassifier
  18. def create_model():
  19.     # create model
  20.     len_token = len(counts)
  21.     model = Sequential()
  22.     model.add(layers.Dense(10,activation='relu',kernel_regularizer=regularizers.l2(0.001),
  23.                            input_shape=(len_token,))) # there are 5191 inputs ! => 10 nodes
  24.     model.add(layers.Dropout(0.6))
  25.     model.add(layers.Dense(10,activation='relu',kernel_regularizer=regularizers.l2(0.001)))
  26.     model.add(layers.Dropout(0.5))
  27.     model.add(layers.Dense(2,activation='sigmoid')) # there are 2 probability outputs! try 'selu'
  28.     model.compile(optimizer='rmsprop',loss='mse',metrics=['accuracy']) #try adamax
  29.     return model
  30.  
  31. # create model
  32. model = KerasRegressor(build_fn=create_model, epochs=20, batch_size=10, verbose=0)
  33.  
  34. # evaluate using 10-fold cross validation
  35. kfold = KFold(n_splits=5, shuffle=True, random_state=1)
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