""":param trainX: training data set:param trainY: expect value of training data:param testX: test data set:param testY: epect value of test data:return: model after training"""
print "Training model is LSTM network!"
input_dim = trainX[1].shape[1]
output_dim = trainY.shape[1] # one-hot label
# print predefined parameters of current model:
model = Sequential()# applying a LSTM layer with x dim output and y dim input. Use dropout parameter to avoid overfitting
model.add(LSTM(output_dim=self.output_dim,
input_dim=input_dim,
activation=self.activation_lstm,
dropout_U=self.drop_out,
return_sequences=True))for i in range(self.lstm_layer-2):
model.add(LSTM(output_dim=self.output_dim,
input_dim=self.output_dim,
activation=self.activation_lstm,
dropout_U=self.drop_out,
return_sequences=True))# argument return_sequences should be false in last lstm layer to avoid input dimension incompatibility with dense layer
model.add(LSTM(output_dim=self.output_dim,
input_dim=self.output_dim,
activation=self.activation_lstm,
dropout_U=self.drop_out))for i in range(self.dense_layer-1):
model.add(Dense(output_dim=self.output_dim,
activation=self.activation_last))
model.add(Dense(output_dim=output_dim,
input_dim=self.output_dim,
activation=self.activation_last))# configure the learning process
model.compile(loss=self.loss, optimizer=self.optimizer, metrics=['accuracy'])# train the model with fixed number of epoches
model.fit(x=trainX, y=trainY, nb_epoch=self.nb_epoch, batch_size=self.batch_size, validation_data=https://www.04ip.com/post/(testX, testY))# store model to json file
model_json = model.to_json()with open(model_path, "w") as json_file:
json_file.write(model_json)# store model weights to hdf5 file
if model_weight_path:if os.path.exists(model_weight_path):
os.remove(model_weight_path)
model.save_weights(model_weight_path) # eg: model_weight.h5
return model
这里写的只涉及LSTM网络的结构搭建 , 至于如何把数据处理规范化成网络所需的结构以及把模型预测结果与实际值比较统计的可视化,就需要根据实际情况做调整了 。
python中predict函数在哪个库一般来说predict函数都是要import一些机器学习算法库后用于建模后预测用的 。比如说sklearn库里面的回归,分类,聚类等等都是有对应predict函数的 。
举个最简单的例子:
线性回归的函数可以在C:\Python27\Lib\site-packages\sklearn\linear_model文件夹中找到 。脚本名为base.py,predict()在187行就有 。
python 时间序列模型中forecast和predict的区别举一个例子吧,比如月度的数据,就是周期为12 , 它有季节影响 。先对其1阶12步差分 , 通过看acf pac f看是简单加法模型 , 还是乘法季节模型 如果是乘法模型那就要对季节部分模拟arima模型 季节部分的arima是以周期位置的acf pacf
python 8个常用内置函数解说8个超好用内置函数set() , eval(),sorted(),reversed(),map(),reduce() , filter() , enumerate()
python中有许多内置函数,不像print那么广为人知,但它们却异常的强大,用好了可以大大提高代码效率 。
这次来梳理下8个好用的python内置函数
1、set()
当需要对一个列表进行去重操作的时候 , set()函数就派上用场了 。
用于创建一个集合,集合里的元素是无序且不重复的 。集合对象创建后,还能使用并集、交集、差集功能 。
2、eval()之前有人问如何用python写一个四则运算器,输入字符串公式,直接产生结果 。用eval()来做就很简单:eval(str_expression)作用是将字符串转换成表达式,并且执行 。
3、sorted()在处理数据过程中,我们经常会用到排序操作,比如将列表、字典、元组里面的元素正/倒排序 。这时候就需要用到sorted(),它可以对任何可迭代对象进行排序,并返回列表 。对列表升序操作:
- mysqli获取所有数据 mysql的提取函数
- mysql 分组函数 mysql分组取数据
- mysql统计函数
- mysql有rank函数吗 mysql有rank
- mongdb python pythonmongodb操作
- redis-cli命令不能用 redis函数调用失败
- mysql的判断函数 mysql怎么判断奇偶数
- mysql数据库编码格式查询 mysql编码函数
- mysql日期yyyymmdd mysql中的日期型函数
- mysql序列函数 mysql如何查序列
