利用PythonOrange结合DNA序列进行人种预测
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用PythonOrange结合DNA序列进行人种预测相关的知识,希望对你有一定的参考价值。
http://blog.csdn.net/jj12345jj198999/article/details/8951120
coursera上 web intelligence and big data 终于布置了HW7,这一次的要求是对一系列DNA序列进行预测,具体说明如下:
Data Analytics Assignment (for HW7)
============================================
Data Sets
-----------
The training set is available here: genestrain.tab.zip (6.2 Mb)
The test set is available here: genesblind.tab.zip (1.2 Mb)
(Note: Data sets are .tab files in the tab-separated format that can be read into Orange):
Entries in the second header line indicate the type of column (in this case all features are ‘discrete‘).
Entries in the third header line indicate the nature of each column:
A ‘ ‘ for most columns that contain a feature, and ‘class‘ for the first column as it contains the actual class labels (i.e., ethnicities of the individuals in each row).
In the training set file the first column, which denotes the class label, is a three-letter code with one of the following values:
o GIH is Gujarati Indian from Houston
o JPT is Japanese in Tokyo
o ASW is Americans of African Ancestry
o YRI is Yoruba in Ibadan, Nigera
=========================
For the purposes of your HW answer alone, each three letter code is to be marked with a NUMERIC VALUE as indicated in the table below:
o CEU is Northern and Western European - 0
o GIH is Gujarati Indian from Houston - 1
o JPT is Japanese in Tokyo - 2
o ASW is Americans of African Ancestry - 3
o YRI is Yoruba in Ibadan, Nigera - 4
YOU MUST USE THE ABOVE NUMERIC VALUES TO ENCODE YOUR ANSWER. Note: This numeric value has no presence in the test or training data.
不过很多人在discussion form里面反映着印度老师在描述的时候没有把问题讲明白(主要是没告诉他们该怎么做),也没在video里面给个指导视频啥的。好在把数据下下来以后,发现其中有一个训练集,一个预测集,估计也只能是先训练,再预测而已。
训练集是一个tab文件,格式如下:
横坐标class代表人种(这里有139行,代表139个训练数据),纵坐标代表DNA片段(约有20万个,后面n列未列出)
预测集如下:
这里第一列加 问号 的就是要预测的,总共为11个人种信息。
了解完数据的情况后,下一步就是看如何来训练和预测了,discussion form中有人提出了用Orange这个库,基友Python,使用起来很方便,地址是 http://orange.biolab.si/doc/ofb/c_basics.htm ,更详细的可以看 http://orange.biolab.si/docs/latest/tutorial/rst/classification/
针对这个问题,贝叶斯分类器就能搞定了,代码很短如下:
- # Description: Read data, build naive Bayesian classifier and classify first few instances
- # Category: modelling
- # Uses: genestrain.tab
- # Predict: genesblind.tab
- # Referenced: c_basics.htm
- import orange
- data = orange.ExampleTable("genestrain")
- data2= orange.ExampleTable("genesblind")
- classifier = orange.BayesLearner(data)
- i = 0
- for item in data2:
- c = classifier(item)
- print "%d: %s " % (i, c)
- i = i + 1
可以看到这里先用训练数据进行训练,得到分类器,然后用分类器对预测数据的每一行进行预测,输出结果,思想还是比较清晰的,不过唯一的缺点是在数据量稍大一点时,运行速度和消耗资源很大,针对这题要使用1G内存,运行10分钟:
最终输出结果如下:
这样就得到了有待预测的11个人种,填写答案搞定。
估计这是这门课最后一次编程作业了,还剩一个在线的final exam,赶紧结课吧。
以上是关于利用PythonOrange结合DNA序列进行人种预测的主要内容,如果未能解决你的问题,请参考以下文章