def evaluate(X, args):
enum = ShuffleSplit(len(X), n_iter=args.n_iterations, test_size=args.test_size)
train_scores = []
test_scores = []
for train_index, test_index in enum:
X_train = [X[idx] for idx in train_index]
X_test = [X[idx] for idx in test_index]
X_train, X_test = preprocess_datasets(X_train, X_test, args)
model = GaussianHMM(n_states=args.n_states, n_training_iterations=args.n_training_iterations,
topology=args.topology)
model.fit(X_train)
train_scores.extend([model.loglikelihood(X_curr) for X_curr in X_train])
test_scores.extend([model.loglikelihood(X_curr) for X_curr in X_test])
train_scores_array = np.array(train_scores)
train_mean = float(np.mean(train_scores_array))
train_std = float(np.std(train_scores_array))
test_scores_array = np.array(test_scores)
test_mean = float(np.mean(test_scores_array))
test_std = float(np.std(test_scores_array))
return train_mean, train_std, test_mean, test_std
evaluate_features.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录