如何利用神经网络做回归问题(全连接以及一维卷积)

源码、留给自己看的
博客地址:http://blog.csdn.net/shizhengxin123/article/details/76147022
1、全连接 回归

from keras.layers import Input, Dense
from keras.models import Model
from keras.layers.core import Flatten, Dense, Dropout,Activation
from keras.layers.normalization import  BatchNormalization  as bn
from  keras.layers.pooling import MaxPooling1D as pool
# This returns a tensor
inputs = Input(shape=(72,))
import  keras.utils 
# a layer instance is callable on a tensor, and returns a tensor
x = Dense(256)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(256)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(128)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(128)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(128)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(128)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(64)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(64)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(64)(x)
x = bn()(x)
x = Activation('relu')(x)
x = Dense(32)(x)
x = bn()(x)
x = Activation('relu')(x)
predictions = Dense(1, activation='linear')(x)

# This creates a model that includes
# the Input layer and three Dense layers
model = Model(input=inputs, output=predictions)
model.compile(optimizer='rmsprop',
              loss='mean_squared_error',
             metrics=['mae', 'acc'])

model.fit(train_x,train_y, validation_data=(test_x, test_y),
          nb_epoch=40, batch_size=10000)

2、一维卷积

from keras.layers import Input, Dense
from keras.models import Model
from keras.layers.core import Flatten, Dense, Dropout,Activation
from keras.layers.normalization import  BatchNormalization  as bn
from  keras.layers.pooling import MaxPooling1D as pool
from keras.layers.convolutional import Conv1D as cnn1
# This returns a tensor
inputs = Input(shape=(72,1))
import  keras.utils 
# a layer instance is callable on a tensor, and returns a tensor
x = cnn1(64,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = cnn1(64,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = pool()(x)
x = cnn1(128,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = cnn1(128,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = pool()(x)
x = cnn1(256,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)

x = cnn1(256,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)

x = cnn1(256,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = pool()(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)

# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = pool()(x)

# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = pool()(x)
x = Flatten()(x)
x = Dense(512)(x)
x = bn()(x)
x = Activation('relu')(x)
predictions = Dense(1, activation='linear')(x)

# This creates a model that includes
# the Input layer and three Dense layers
model = Model(input=inputs, output=predictions)
model.compile(optimizer='rmsprop',
              loss='mean_squared_error',
             metrics=['mae', 'acc'])
model.fit(train_x,train_y, validation_data=(test_x, test_y),
          nb_epoch=40, batch_size=10000)
# model.save_weights('/home/etcp/szx/flower_data/third_park_predict.h5')
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值