lhyljyt Goto Github PK
Type: User
Type: User
确定需要的变量,并使用相关数据库。建立字典、列表(names、relationship、line_names)储存名字,关系。在此之前需要建立一个关于《黎明破晓的街道》的主要角色名称TXT文档,我将之命名为Introduction to key people.txt 。文本中实体识别。读入《黎明破晓的街道》剧本的每一行,对其做分词,判断该词的词性是不是“人名”(nr作用:判断是否是人名),提取每段人物,存入line_names。根据识别结果构建网络。对于 lineNames 中每一行,我们为该行中出现的所有人物两两相连。如果两个人物之间尚未有边建立,则将新建的边权值设为 1,否则将已存在的边的权值加 1。这种方法将产生很多的冗余边,这些冗余边将在最后处理。过滤冗余边。将已经建好的 names 和 relationships 输出到文本,以方便 gephi 可视化处理。输出边的过程中可以过滤可能是冗余的边,这里假设共同出现次数少于 10 次的是冗余边,则在输出时跳过这样的边。输出结果。由于gephi导入电子表格,故生成文件扩展名为csv。输出的节点集合保存为 黎明破晓的街道_node.csv ,边集合保存为 黎明破晓的街道_edge.csv。运行。会在相应文件夹python综合项目中生成黎明破晓的街道_node.csv、黎明破晓的街道_edge.csv 。使用gephi生成可视化网络。
#coding:gbk """ 第一个小项目:rock石头-paper纸-scissors剪刀-lizard蜥蜴-Spock史波克 作者:梁鹤逸 日期:2019.11.13 """ # 0 - 石头 # 1 - 史波克 # 2 - 纸 # 3 - 蜥蜴 # 4 - 剪刀 import random tag=1 list1=['石头','史波克','纸','蜥蜴','剪刀'] # 对程序进行测试 def name_to_number(name):#将用户的游戏选择对象转换为相应的整数 if name=='石头': return 0 elif name=='史波克': return 1 elif name=='纸': return 2 elif name=='蜥蜴': return 3 elif name=='剪刀': return 4 else: print('Error: No Correct Name') def number_to_name(number): if number in range(0,5): if number==0: return 石头 elif number==1: return 史波克 elif number==2: return 纸 elif number==3: return 蜥蜴 elif number==4: return 剪刀 else: print('Error: No Correct Name') def rpsls(player_choice,computer):#用户玩家任意给出一个选择,根据RPSLS游戏规则,在屏幕上输出对应的结果 while tag: list1=['石头','史波克','纸','蜥蜴','剪刀'] list2=[[0,4],[0,3],[1,4],[1,0],[2,0],[2,1],[3,2],[3,1],[4,3],[4,2]] if player_choice in list1: if [player_choice,computer]in list2: print('您赢了') elif player_choice==computer: print('您和计算机出的一样呢') else: print('计算机赢了') else: print('Error: No Correct Name') break print("欢迎使用RPSLS游戏") print("----------------") print("请输入您的选择:") player_choice=input() print("--------") computer=random.choice(list1) print('你的选择为:%s'%(player_choice)) print('计算机的选择为:%s'%(computer)) rpsls(player_choice,computer)#rpsls意为石头剪刀布 # 输出"-------- "进行分割 # 显示用户输入提示,用户通过键盘将自己的游戏选择对象输入,存入变量player_choice # 调用name_to_number()函数将用户的游戏选择对象转换为相应的整数,存入变量player_choice_number # 利用random.randrange()自动产生0-4之间的随机整数,作为计算机随机选择的游戏对象,存入变量comp_number # 调用number_to_name()函数将计算机产生的随机数转换为对应的游戏对象 # 在屏幕上显示计算机选择的随机对象 # 利用if/elif/else 语句,根据RPSLS规则对用户选择和计算机选择进行判断,并在屏幕上显示判断结果 # 如果用户和计算机选择一样,则显示“您和计算机出的一样呢”,如果用户获胜,则显示“您赢了”,反之则显示“计算机赢了” #根据以上提示编写执行代码,代码完成后删除掉pass #list2=[[0,4],[0,3],[1,4],[1,0],[2,0],[2,1],[3,2],[3,1],[4,3],[4,2]] #[['石头','剪刀'],['石头','蜥蜴'],['史波克','剪刀'],['史波克','石头'],['布','石头'],['布','史波克'],['蜥蜴','布'],['蜥蜴','史波克'],['剪刀','蜥蜴'],['剪刀','布']]
程序运行输出:① 葡萄各参数指标的描述性统计结果;② 3个葡萄品种的每个指标对比图(5个指标,需5幅图);③ 模型的精度值;④ 模型预测分类的结果(需输出品种具体的中文名)。 6. 法国红酒数据集(frenchwine.csv)说明:本数据集一共包括178条数据,3种葡萄品种,即仙粉黛(Zinfandel),西拉(Syrah),赤霞珠(Sauvignon),每个品种数据均包括5项指标(酒精含量alcohol、酸度malic_acid、灰份ash、灰分碱度alcalinity ash,镁含量magnesium)。 7. 需要用到的第三方库资源参考: Sklearn库官方文档:https://scikit-learn.org/stable/ ,https://sklearn.apachecn.org/ Pandas库官方中文文档:https://www.pypandas.cn/ Numpy库官方中文文档: https://www.numpy.org.cn/ Matplotlib库官方中文文档:https://www.matplotlib.org.cn/ Seaborn库官方文档:http://seaborn.pydata.org/, https://github.com/apachecn/seaborn-doc-zh
#coding:gbk """ 利用决策树算法进行分类 作者:梁鹤逸 日期:2019.12.14 """ import pandas as pd # 调入需要用的库 import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm import seaborn as sb #%matplotlib inline # 调入数据 df = pd.read_csv('G:\\zy\\python‘s程序\\frenchwine.csv') df.columns = ['species','alcohol', 'malic_acid', 'ash', 'alcalinity ash', 'magnesium'] # 查看前5条数据 df.head() print(df.head()) # 查看数据描述性统计信息 df.describe() print(df.describe()) def scatter_plot_by_category(feat, x, y): #数据的可视化 alpha = 0.5 gs = df.groupby(feat) cs = cm.rainbow(np.linspace(0, 1, len(gs))) for g, c in zip(gs, cs): plt.scatter(g[1][x], g[1][y], color=c, alpha=alpha) plt.figure(figsize=(20,5)) plt.subplot(131) scatter_plot_by_category('species', 'alcohol', 'ash') plt.xlabel('alcohol') plt.ylabel('ash') plt.title('species') plt.show() plt.figure(figsize=(20, 10)) #利用seaborn库绘制三种Iris花不同参数图 for column_index, column in enumerate(df.columns): if column == 'species': continue plt.subplot(2, 3, column_index + 1) sb.violinplot(x='species', y=column, data=df) plt.show() # 首先对数据进行切分,即划分出训练集和测试集 from sklearn.model_selection import train_test_split #调入sklearn库中交叉检验,划分训练集和测试集 all_inputs = df[['alcohol', 'malic_acid', 'ash', 'alcalinity ash','magnesium']].values all_species = df['species'].values (X_train, X_test, Y_train, Y_test) = train_test_split(all_inputs, all_species, train_size=0.85, random_state=1)#80%的数据选为训练集 # 使用决策树算法进行训练 from sklearn.tree import DecisionTreeClassifier #调入sklearn库中的DecisionTreeClassifier来构建决策树 # 定义一个决策树对象 decision_tree_classifier = DecisionTreeClassifier() # 训练模型 model = decision_tree_classifier.fit(X_train, Y_train) # 输出模型的准确度 print(decision_tree_classifier.score(X_test, Y_test)) # 使用训练的模型进行预测,为了方便, # 案例直接把测试集里面的数据拿出来三条 print(X_test[0:3])#利用3个数据进行测试,即取3个数据作为模型的输入端 model.predict(X_test[0:3]) print(model.predict(X_test[0:3]))#输出测试的结果,即输出模型预测的结 for all_species in range(1): print('仙粉,黛西拉,赤霞珠')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.