我正在使用Kaggle - 心血管疾病数据集中的数据集。模型已经过训练,我想做的是标记以动态方式插入的单个输入(一行13个值)。
数据集的形状为 13 个特征 + 1 个目标,66k 行
#prepare dataset for train and test
dfCardio = load_csv("cleanCardio.csv")
y = dfCardio['cardio']
x = dfCardio.drop('cardio',axis = 1, inplace=False)
model = knn = KNeighborsClassifier()
x_train,x_test, y_train, y_test = train_test_split(x,y,test_size=0.2,random_state=42)
model.fit(x_train, y_train)
# make predictions for test data
y_pred = model.predict(x_test)
predictions = [round(value) for value in y_pred]
# evaluate predictions
accuracy = accuracy_score(y_test, predictions)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
ML是训练的,我想做的是预测这一行的标签:
['69','1','151','22','37','0','65','140','90','2','1','0','0','1']
为目标返回 0 或 1。所以我写了这个代码:
import numpy as np
import pandas as pd
single = np.array(['69','1','151','22','37','0','65','140','90','2','1','0','0','1'])
singledf = pd.DataFrame(single)
final=singledf.transpose()
prediction = model.predict(final)
print(prediction)
但它给出了错误:查询数据维度必须与训练数据维度匹配
如何修复单行的标签?为什么我无法预测单个病例?
弑天下
叮当猫咪
慕的地6264312
相关分类