本文介绍了如何计算模型的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了极限学习机(ELM)算法.我想计算出训练时间..我的问题是我得到了训练时间0:00:00,我怀疑这个结果不正确
I used Extreme Learning Machine (ELM) algorithm. And I want to calculate training time..my problem is I got training time 0:00:00 and I a doubt this result is not correct
我的代码:
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from scipy.linalg import pinv2
import time
#import dataset
train = pd.read_excel('INRStrai.xlsx')
test = pd.read_excel('INRStes.xlsx')
#scaler data
scaler = MinMaxScaler()
X_train = scaler.fit_transform(train.values[:,1:])
y_train = scaler.fit_transform(train.values[:,:1])
X_test = scaler.fit_transform(test.values[:,1:])
y_test = scaler.fit_transform(test.values[:,:1])
#input size
input_size = X_train.shape[1]
#Number of neurons
hidden_size = 300
#weights & biases
input_weights = np.random.normal(size=[input_size,hidden_size])
biases = np.random.normal(size=[hidden_size])
#Activation Function
def relu(x):
return np.maximum(x, 0, x)
#Calculations
def hidden_nodes(X):
G = np.dot(X, input_weights)
G = G + biases
H = relu(G)
from datetime import timedelta
start_time = time.time()
# Perform lots of computations.
elapsed_time_secs = time.time() - start_time
msg = "Execution took: %s secs (Wall clock time)" % timedelta(seconds=round(elapsed_time_secs))
print(msg)
我得到了执行时间:0:00:00秒,我怀疑执行时间不正确,为什么我要花点时间
I got the execution time: 0:00:00 secs ,I a doubt execution time is not correct, why I got this result for time
推荐答案
我使用以下方法来计算运行时间:
I've used the following to calculate running time:
from datetime import datetime as dt
start = dt.now()
# process stuff
running_secs = (dt.now() - start).seconds
这篇关于如何计算模型的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!