keras artificial neural network to build entry

//2019.07.29-30
1, Keras is to provide some highly available neural network framework API Python , can help you quickly build and train their depth learning model, its back end is TensorFlow or Theano .


2, Keras is considered to be in the future to build neural networks, the following are some of its popular reasons:
(1) lightweight and fast development : Keras is aimed at the elimination of boilerplate code. Keras few lines of code to implement more features than TensorFlow code for native. You can also easily achieve CNN and RNN, and let them run in CPU or GPU above.
(2) the framework of "winner" : Keras is an API, runs on top of other deep learning framework. This framework can be TensorFlow or Theano. Microsoft also plans to make CNTK as a back end of Keras. Currently, the neural network framework of the World is very fragmented, and growing very fast.
Imagine, every year we have to learn a new framework, which is how painful yes. So far, TensorFlow seems to be a trend, and more and more began to provide support for the framework Keras, it could become a standard.
3, at present, Keras depth is one of the fastest growing learning framework . Because you can use a different depth learning framework as a backend, which also makes it a popular big reason. You can imagine such a scenario, if you read an article very interesting paper, and you want to test this model in your own data set above. Let's assume again, you are very familiar with TensorFlow, but Theano know very little. So, you have to use TensorFlow reproduction of this thesis, but this period is very long. However, if the code is now written using Keras, then you just modify the back-end TensorFlow can use code. It would be a huge boost for community development.


4, using the theano Keras artificial neural network to build a framework for:
Import numpy AS NP
Import PANDAS AS PD
from the Sequential keras.models Import
from the Dense keras.layers Import, Activation
from the SGD keras.optimizers Import
from sklearn.datasets # Import load_iris introduced Keras artificial neural network building blocks and introducing the raw data
IRIS = load_iris ()
Print (IRIS [ "target"])
from sklearn.preprocessing import LabelBinarizer
Print (LabelBinarizer (). fit_transform (IRIS [ "target"]))
from sklearn.model_selection import train_test_split
train_data, TEST_DATA, train_target, test_target = train_test_split (iris.data, iris.target, test_size = 0.2, = random_state. 1)
labels_train LabelBinarizer = (). fit_transform (train_target)
labels_test LabelBinarizer = (). fit_transform (test_target)

model=Sequential(
[
Dense(5,input_dim=4),
Activation("relu"),
Dense(3),
Activation("sigmoid"), #搭建数据神经网络的结构(输入输出的形式和数量)
]
)
#model=Sequential()
sgd=SGD(lr=0.01,decay=1e-6,momentum=0.9,nesterov=True)
model.compile(optimizer=sgd,loss="categorical_crossentropy")
model.fit(train_data,labels_train,nb_epoch=200,batch_size=40) #进行数据的训练
print(model.predict_classes(test_data)) #输出测试集的预测结果

Guess you like

Origin www.cnblogs.com/Yanjy-OnlyOne/p/11269454.html