**valueerror:不支持多类多输出**knn python

9nvpjoqh  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(273)

我正在用python编写knn。任何能帮我的人。
我的代码
导入numpy作为np导入pandas作为pd从sklearn.model\u selection导入train\u test\u split从sklearn.preprocessing导入matplotlib.pyplot作为plt从sklearn.neighborsClassifier从sklearn.metrics导入conflusion\u matrix导入pickle从sklearn.model\u selection导入gridsearchcv从sklearn.multioutput导入multioutputclassifier


# training/validation set

train_set = pd.read_csv("trainingtesting.csv")

# test set

test_set = pd.read_csv("validation.csv")

X = train_set.iloc[:,0:1].values  #RSSI
Y = train_set.iloc[:,1:3].values   #X,Y (OUTCOME)

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=0)

# print(X_train.shape)

# print(Y_test)

# print(Y_train)

sc = StandardScaler()                #feature scalin
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

# import math

# print(math.sqrt(len(Y_test)))

classifier = KNeighborsClassifier(n_neighbors=1, p=3, metric='euclidean')
classifier.fit(X_train, Y_train)

# Save the trained model as a pickle string.

saved_model = pickle.dumps (classifier)

# Load the pickled model

classifier_from_pickle = pickle.loads(saved_model)

# Use the loaded pickled model to make predictions

classifier_from_pickle.predict(X_test)

Y_pred = classifier.predict(X_test)

# print(Y_pred)

cm = confusion_matrix(Y_test, Y_pred)
print(cm)

error cm=confusion\u matrix(y\u test,y\u pred)file“c:\users\92316\appdata\local\programs\python37\lib\site packages\sklearn\metrics\u classification.py”,第268行,在confusion\u matrix y\u type中,y\u true,y\u pred=\u check\u targets(y\u true,y\u pred)文件“c:\users\92316\appdata\local\programs\python37\lib\site packages\sklearn\metrics\u classification.py”,第97行,在检查目标中
raise valueerror(“{0}不受支持”。format(y\u type))valueerror:不支持多类多输出

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题