首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python列表追加时出现颠簸数组错误

Python列表追加时出现颠簸数组错误
EN

Stack Overflow用户
提问于 2018-07-21 02:46:35
回答 1查看 131关注 0票数 0

我正在尝试使用list append函数将列表追加到列表中。

但got错误显示列表索引必须是整数或切片,而不是元组。不知道为什么。

pca_components = range(1,51)
gmm_components = range(1,5)
covariance_types = ['spherical', 'diag', 'tied', 'full']

# Spherical
spherical_results = []
for i in pca_components:
    pca_model = PCA(n_components=i)
    pca_train = pca_model.fit(train_data).transform(train_data)
    for j in gmm_components:
        parameters = (i+i)*j*2
        if parameters > 50:
            pass
        else:             
            gmm_model = GMM(n_components=j, covariance_type='spherical')
            gmm_model.fit(pca_train)
            pca_test = pca_model.transform(test_data)
            predictions = gmm_model.predict(pca_test)
            accuracy = np.mean(predictions.ravel() == test_labels.ravel())
            accuracy=int(accuracy)
            spherical_results.append([accuracy, i,j, parameters])
spher_results = np.array(spherical_results)
max_accuracy = np.amax(spherical_results[:,0])
print(f"highest accuracy score for spherical is {max_accuracy}")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-21 03:30:02

这行的目的是什么?

spher_results = np.array(spherical_results)

它从一个列表中生成一个数组。但是在下面的代码中没有使用spher_results

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51448700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档