Dense全连接层
Activation激活层
SGD随机梯度下降算法
标签先独热码化
给你们代码,写的啥咱也不知道,咱也不敢问 # __author__ = 'aaron' __date__ = '7/20/2019 11:19 AM' import numpy from keras.models import Sequential from keras.layers import Dense, Activation from keras.optimizers import SGD def main(): from sklearn.datasets import load_iris 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"), ] ) 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)) if __name__ == "__main__": main()
由于Anaconda不包含keras,所以需要额外安装,操作如下:
markmark
keras安装