Keras Develop a neural network

Source: Internet
Author: User
Tags theano keras

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

    1. Load the data.
    2. Define the model.
    3. Compile the model.
    4. Fit the model.
    5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.