Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用数组重塑数据。如果数据只有一个特征,则重塑(-1,1)_Python_Machine Learning_Scikit Learn_Computer Vision_Reshape - Fatal编程技术网

Python 使用数组重塑数据。如果数据只有一个特征,则重塑(-1,1)

Python 使用数组重塑数据。如果数据只有一个特征,则重塑(-1,1),python,machine-learning,scikit-learn,computer-vision,reshape,Python,Machine Learning,Scikit Learn,Computer Vision,Reshape,我如何在一个数据集上使用metrics.silouhette_分数,该数据集有1300个图像,它们的ResNet50特征向量每个长度为2048,离散类标签介于1到9之间 import pandas as pd import numpy as np from sklearn.metrics import pairwise_distances from sklearn import cluster, datasets, preprocessing, metrics from sklearn.clus

我如何在一个数据集上使用metrics.silouhette_分数,该数据集有1300个图像,它们的ResNet50特征向量每个长度为2048,离散类标签介于1到9之间

import pandas as pd
import numpy as np
from sklearn.metrics import pairwise_distances
from sklearn import cluster, datasets, preprocessing, metrics
from sklearn.cluster import KMeans
df = pd.read_csv("master.csv")
labels = list(df['Q3 Theme1'])
labels_reshaped = np.ndarray(labels).reshape(-1,1)
X = open('entire_dataset__resnet50_feature_vectors.txt')
X_Data = X.read()
print('Silhouette Score:', metrics.silhouette_score(X_Data, labels_reshaped,
                                                    metric='cosine'))
我得到这个错误:

Traceback (most recent call last):
  File "/dataset/silouhette_score.py", line 8, in <module>
    labels_reshaped = np.ndarray(labels).reshape(-1,1)
ValueError: sequence too large; cannot be greater than 32

Process finished with exit code 1
Traceback (most recent call last):
  File "/dataset/silouhette_score.py", line 8, in <module>
    labels_reshaped = np.ndarray(labels).reshape(1,-1)
ValueError: sequence too large; cannot be greater than 32

Process finished with exit code 1
我得到这个错误:

Traceback (most recent call last):
  File "/dataset/silouhette_score.py", line 8, in <module>
    labels_reshaped = np.ndarray(labels).reshape(-1,1)
ValueError: sequence too large; cannot be greater than 32

Process finished with exit code 1
Traceback (most recent call last):
  File "/dataset/silouhette_score.py", line 8, in <module>
    labels_reshaped = np.ndarray(labels).reshape(1,-1)
ValueError: sequence too large; cannot be greater than 32

Process finished with exit code 1
我将此作为输出:

如何修复此代码,以便打印单个轮廓分数

Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Process finished with exit code 1

我在这里粘贴了一行我的特征向量文件.txt文件:由2048个由空格分隔的数字组成

我最终能够弄明白这一点。我需要创建与sklearn所需格式相同的特征向量:

import pandas as pd
from sklearn import metrics


df = pd.read_csv("master.csv")
labels = list(df['Q3 Theme1'])
X = open('entire_dataset__resnet50_feature_vectors.txt')
#X_Data = X.read()

fv = []
for line in X:
    line = line.strip("\n")
    tmp_arr = line.split(' ')
    print(tmp_arr)
    fv.append(tmp_arr)

print(fv)
print('Silhouette Score:', metrics.silhouette_score(fv, labels,
                                                    metric='cosine'))