【发布时间】:2019-07-31 05:52:40
【问题描述】:
我正在尝试根据预先指定的标签对数据进行分类。
有两列如下所示:
room_class room_cluster
Standard single sea view Standard
Deluxe twin Single Deluxe
Suite Superior room ocean view Suite
Superior Double twin Superior
Deluxe Double room Deluxe
如上图标签集中的 room_cluster 所示。
sn-p代码如下:
le = preprocessing.LabelEncoder()
datar = df
#### Separate data into feature and Labels
x = datar.room_class
y = datar.room_cluster
#### Using Label encoder to change string onto 'int'
le.fit(x)
addv = le.transform(x)
asb = addv.reshape(-1,1)
#### Splitting into training and testing set adn then using Knn
x_train,x_test,y_train,y_test=train_test_split(asb,y,test_size=0.40)
classifier=neighbors.KNeighborsClassifier(n_neighbors=3)
classifier.fit(x_train,y_train)
predictions = classifier.predict(x_test)
#### Checking the accuracy
print(accuracy_score(y_test,predictions))
我得到的测试数据的准确率只有 78%,代码中是否有问题阻碍了准确度。
如何使用此模型来预测自定义功能,例如:
输入:'Suite Single sea view'
输出:'Suite'
输入:'Superior Suite twin'
输出:“高级”
【问题讨论】:
-
您将 78% 的准确率视为“低”这一事实在任何情况下都不一定意味着这里存在任何 编码 问题,这就是(编码问题)关于...
-
我需要 ML,因为输入数据可能会有所不同,但是如何使用模型进行预测作为问题中的示例?
-
@Justice_Lords room_class 并不总是由两个词组成,请查看编辑。
-
@Justice_Lords 如果可能的话,您能否以答案的形式提供示例代码 sn-p?并且“填充所有句子” = 使它们具有相同的结构?
标签: python machine-learning scikit-learn classification knn