如何通过属性问题区分动物

我正在开发一个程序,实际上是一个人工智能,它通过一系列问题来学习区分动物,这些问题将确定我们所考虑的动物所具有的属性。因此,我需要一种方法来存储动物及其相应的属性问题,例如:

dog : does it have a wet nose?      does it have whiskers?

所有回答“是”的问题都是狗所具有的属性……有什么建议吗?另外,请注意一些动物可能具有相同的属性,例如:

dog : does it have a wet nose?      does it have whiskers?cat : does it purr?      does it have whiskers?

所以我希望程序能够通过问多个问题来确定哪个动物是哪个。


回答:

最简单的方法是使用字典,它将保持属性与具有该属性的动物列表之间的关系,例如:

attributes=[bite,scratch,purr,whiskers,...]dic={whiskers:[cat,dog]purr:[cat]scratch:[cat]bite:[cat,dog,rat]}dose it scratch

基于你的问题格式,例如:

   for each question:     for each word in question :       if word in attributes:         attributesFound.append(word)   animal=set(dic[attributesFound[0]])   for each attribute in attributesFound:   animal=animal.intersection(dict[attribute ])

假设我们有这种情况

      does it purr?      does it have whiskers?

attributesFound 将会是 [purr,whiskers],animal 将会是 [cat,dog],然后我们进入每个属性的循环

 for each attribute in [cat,dog] :   animal=set(animal.intersection(dict[attribute ]))//在第一次迭代中,animal 仍然是 [cat,dog]。

// 然而在第二次迭代中,set([cat,dog]intersection([cat])) 将只留下一个元素,即 cat

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注