About Keras:
Keras is a high-level neural network API, written in Python and capable of running on TENSORFLOW,CNTK or Theano.
Use the command to install:
Pip Install Keras
Steps to implement deep learning in Keras
- Load the data.
- Define the model.
- Compile the model.
- Fit the model.
- Evaluate the model.
Use the dense class to describe a fully connected layer. We can specify the number of neurons in a layer as the first parameter, specify the initialization method as the second parameter as the INIT, and use the activation parameters to determine the activation function. Now that the model is defined, we can compile it. The build model uses an efficient digital library under the cover (so-called back end), such as Theano or TensorFlow. So far, we have defined our model and compiled it into a valid calculation. Now it's time to run the model on the Pima data. We can train or fit our data model by invoking the Fit () function on the model.
ImportNumPy as NPImportPandas as PDImportKeras fromKeras.modelsImportSequential fromKeras.layersImportDense#Initializing The seed value to a integer.Seed = 7np.random.seed (Seed)#Loading The data set (PIMA diabetes Dataset)DataSet = Pd.read_csv (r'C:/users/administrator/desktop/pima-indians-diabetes.csv') Dataset.head () Dataset.shape#Loading the input values to X and Label values Y using slicing.X = Np.mat (dataset.iloc[:, 0:8]) Y= Np.mat (dataset.iloc[:,8]). Reshape ( -1,1)#Initializing the sequential model from KERAS.Model =Sequential ()#Creating a neuron hidden layer with Linear rectified activation function.Model.add (Dense, input_dim=8, init='Uniform', activation='Relu'))#Creating A 8 neuron hidden layer.Model.add (Dense (8, init='Uniform', activation='Relu'))#Adding a output layer.Model.add (Dense (1, init='Uniform', activation='sigmoid'))#compiling the ModelModel.compile (loss='binary_crossentropy', Optimizer='Adam', metrics=['accuracy'])#Fitting the ModelHistory=model.fit (X, Y, nb_epoch=150, batch_size=10) scores=model.evaluate (X, Y)Print("%s:%.2f%%"% (Model.metrics_names[1], scores[1] * 100))
ImportMatplotlib.pyplot as Pltloss=history.history['Loss']val_loss= history.history['ACC']epochs= Range (1, len (loss) + 1) plt.figure (figsize= (10,6)) Plt.plot (epochs, loss,'Bo', label='Training Loss') Plt.plot (epochs, Val_loss,'R', label='ACC') Plt.legend () plt.show ()
Keras Develop a neural network