%matplotlib inline import keras from keras.models import Sequential from keras.callbacks import EarlyStopping from keras.layers import Activation, Dropout, BatchNormalization, Dense #from keras.layers.noise import GaussianDropout from keras.regularizers import l1_l2 import pandas as pd import numpy as np dropout_rate = 0.3 L1, L2 = 1e-6, 1e-6 dataset = pd.read_csv('train.csv') X=dataset.iloc[:, 0:780].values y=dataset.iloc[:, 780].values y=y[:-1] X=X[:-1] import sklearn.preprocessing onehot = sklearn.preprocessing.OneHotEncoder(sparse=False) y = onehot.fit_transform(y.reshape((-1, 1))).astype(np.float64) print (y) #(59999, 780) X #(59999, 10) y # from sklearn.model_selection import train_test_split #X-train, X-test , y-train, y-test = train_test_split(X, y, test_size = 0.2, random_state = 0) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) from sklearn.preprocessing import StandardScaler #sc = StandardScaler() #X_train = sc.fit_transform(X_train) #X_test = sc.transform(X_test) from keras.wrappers.scikit_learn import KerasClassifier from sklearn.model_selection import GridSearchCV from keras.models import Sequential from keras.layers import Dense classifier = Sequential() # Adding the input layer and the first hidden layer classifier.add(Dense(units = 395, kernel_initializer = 'uniform', activation = 'relu', input_dim = 780, kernel_regularizer = l1_l2(l1=L1, l2=L2) )) # Adding the second hidden layer classifier.add(Dense(units = 600, kernel_initializer = 'uniform', activation = 'relu',kernel_regularizer = l1_l2(L1, L2))) classifier.add(Dense(units = 600, kernel_initializer = 'uniform', activation = 'relu',kernel_regularizer = l1_l2(L1, L2))) classifier.add(Dense(units = 600, kernel_initializer = 'uniform', activation = 'relu',kernel_regularizer = l1_l2(L1, L2))) classifier.add(Dense(units = 600, kernel_initializer = 'uniform', activation = 'relu',kernel_regularizer = l1_l2(L1, L2))) #classifier.add(Dropout(dropout_rate)) #classifier.add(BatchNormalization()) # Adding the output layer classifier.add(Dense(units = 10, kernel_initializer = 'uniform', activation = 'softmax')) # Compiling the ANN classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy']) early_stopping_monitor = EarlyStopping (patience=2) # Fitting the ANN to the Training set classifier.fit(X_train, y_train, batch_size = 10, epochs = 100 , callbacks= [early_stopping_monitor])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question