资源简介
Python实现动物识别产生式系统,适合初学机器学习者,有应该更正的地方,欢迎指正
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Sun Dec 24 15:13:13 2017
@author: user
“““
import numpy as np
class productionSystem:
def __init__(self):
f=open(“productions.txt““r“)
self.productions=[]
self.charicters=[]
self.myclass=(f.readline().strip(“最终类别为:“).strip()).split(“,“)
for line in f.readlines():
if(line!=‘\n‘):
line=line.replace(“->““ “)
line=line.replace(“““ “)
line=line.split()
self.productions.append(line)
for ch in line:
if (ch not in self.myclass) and (ch not in self.charicters):
self.charicters.append(ch)
def showProduction(self):
print()
def match(selfx):
for ch in self.productions[x][:-1]:
if(ch in self.work):
continue
else:
return False
return True
def classify(selfwork):
used=np.zeros(len(self.productions))
counter=len(self.work)
while(True):
for i in range(len(self.productions)):
if(used[i]==0 and self.match(i)):
used[i]=1
self.work.append(self.productions[i][-1])
if(self.work[-1] in self.myclass):
return True
tmp=len(self.work)
if(tmp==counter):
return False
else:
counter=tmp
def dowork(self):
print(“所有类别有:“)
for t in self.myclass:
print(‘{:<10}‘.format(t)end=““)
print()
print(“所有属性有:“)
counter=0
for t in self.charicters:
counter+=1
if(counter%5==0):
print(‘{:<10}‘.format(t))
else:
print(‘{:<10}‘.format(t)end=‘‘)
self.work=input(“\n请输入属性\n----属性之间用空格隔开----\n“)
self.work=self.work.split()
if(self.classify(self.work)):
print(“该物种为:“+self.work[-1])
else:
print(“抱歉,未能识别出该物种\n“)
def main():
p=productionSystem()
p.dowork()
if __name__==“__main__“:
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 429 2017-12-24 16:24 ProductionSystem\productions.txt
文件 2346 2017-12-24 19:35 ProductionSystem\production_system.py
文件 2225 2017-12-24 18:56 ProductionSystem\__pycache__\production_system.cpython-36.pyc
目录 0 2017-12-24 18:56 ProductionSystem\__pycache__
目录 0 2017-12-24 17:15 ProductionSystem
----------- --------- ---------- ----- ----
5000 5
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论