简介

通过基因表达监测(DNA微阵列)对新的癌症病例进行分类,从而为鉴定新的癌症类别和将肿瘤分配到已知类别提供了一般方法。这些数据用于对患有急性髓性白血病(AML)和急性淋巴细胞白血病(ALL)的患者进行分类。

代码实例


导入依赖库

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

载入数据

labels_df = pd.read_csv('actual.csv', index_col = 'patient')
test_df = pd.read_csv('data_set_ALL_AML_independent.csv')
data_df = pd.read_csv('data_set_ALL_AML_train.csv')
print('train_data: ',  data_df.shape, '\n test_data: ',  test_df.shape, '\n labels: ', labels_df.shape)
# labels_df.shape
data_df.head()   #查看前5行(默认前5行)

清理数据

test_cols_to_drop = [c for c in test_df.columns if 'call' in c]
test_df = test_df.drop(test_cols_to_drop, axis=1)
test_df = test_df.drop(['Gene Description', 'Gene Accession Number'], axis=1 )data_cols_to_drop = [c for c in data_df.columns if 'call' in c]
data_df = data_df.drop(data_cols_to_drop, axis=1)
data_df = data_df.drop(['Gene Description', 'Gene Accession Number'], axis=1 )
print('train_data ', data_df.shape, '\n test_data: ',  test_df.shape,  '\n labels: ', labels_df.shape)
data_df.head()

定义'特征'和'样本'

使用基因表达值来预测癌症类型。 因此,特征是患者的基因和样本。 使用X作为输入数据,其中行是样本(患者),列是特征(基因)。

将'ALLL'替换为0,将'AML'替换为1。

labels_df = labels_df.replace({'ALL':0, 'AML':1})
train_labels = labels_df[labels_df.index <= 38]
test_labels = labels_df[labels_df.index > 38]
print(train_labels.shape, test_labels.shape)
# labels_df.index
test_df = test_df.T
train_df = data_df.T

检查空值

print('Columns containing null values in train and test data are ', data_df.isnull().values.sum(),  test_df.isnull().values.sum())

联合训练集和测试集

full_df = train_df.append(test_df, ignore_index=True)
print(full_df.shape)
full_df.head()

标准化和处理高维度

标准化

所有变量具有非常相似的范围的方式重新调整我们的变量(预测变量)。

高维度

只有72个样本和7000多个变量。 意味着如果采取正确的方法,模型很可能会受到HD的影响。 一个非常常见的技巧是将数据投影到较低维度空间,然后将其用作新变量。 最常见的尺寸减小方法是PCA。

# Standardization
from sklearn import preprocessing
X_std = preprocessing.StandardScaler().fit_transform(full_df)
# Check how the standardized data look like
gene_index = 1
print('mean is : ',  np.mean(X_std[:, gene_index] ) )
print('std is :', np.std(X_std[:, gene_index]))fig= plt.figure(figsize=(10,10))
plt.hist(X_std[:, gene_index], bins=10)
plt.xlim((-4, 4))
plt.xlabel('rescaled expression', size=30)
plt.ylabel('frequency', size=30)

PCA(聚类分析)

# PCAfrom sklearn.decomposition import PCA
pca = PCA(n_components=50, random_state=42)
X_pca = pca.fit_transform(X_std)
print(X_pca.shape)
cum_sum = pca.explained_variance_ratio_.cumsum()
cum_sum = cum_sum*100fig = plt.figure(figsize=(10,10))
plt.bar(range(50), cum_sum)
plt.xlabel('PCA', size=30)
plt.ylabel('Cumulative Explained Varaince', size=30)
plt.title("Around 90% of variance is explained by the First 50 columns ", size=30)

labels = labels_df['cancer'].valuescolors = np.where(labels==0, 'red', 'blue')from mpl_toolkits.mplot3d import Axes3D
plt.clf()
fig = plt.figure(1, figsize=(15,15 ))
ax = Axes3D(fig, elev=-150, azim=110,)
ax.scatter(X_pca[:, 0], X_pca[:, 1], X_pca[:, 2], c=colors, cmap=plt.cm.Paired,linewidths=10)
ax.set_title("First three PCA directions")
ax.set_xlabel("PCA1")
ax.w_xaxis.set_ticklabels([])
ax.set_ylabel("PCA2")
ax.w_yaxis.set_ticklabels([])
ax.set_zlabel("PCA3")
ax.w_zaxis.set_ticklabels([])
plt.show()

RF分类

X = X_pca
y = labels
print(X.shape, y.shape)

划分训练集和测试集

from sklearn.model_selection import train_test_splitX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
print(X_train.shape, y_train.shape)
import seaborn as sns
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
rfc = RandomForestClassifier(random_state=42)
rfc.fit(X_train, y_train)
y_pred = rfc.predict(X_test)
print(accuracy_score(y_test, y_pred))
0.7083333333333334

重要特征

labs = ['PCA'+str(i+1) for i in range(X_train.shape[1])]
importance_df = pd.DataFrame({'feature':labs,'importance': rfc.feature_importances_
})importance_df_sorted = importance_df.sort_values('importance', ascending=False)
importance_df_sorted.head()fig = plt.figure(figsize=(25,10))
sns.barplot(data=importance_df_sorted, x='feature', y='importance')
plt.xlabel('PCAs', size=30)
plt.ylabel('Feature Importance', size=30)
plt.title('RF Feature Importance', size=30)
plt.savefig('RF Feature Importance.png', dpi=300)
plt.show

Confusion Matrix(混淆矩阵)

Gradient Boost Classifier(梯度增强分类器)

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
### Normalize cm, np.newaxis makes to devide each row by the sum
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]print(np.newaxis)
cmap=plt.cm.Bluesplt.imshow(cm, interpolation='nearest', cmap=cmap)
print(cm)

from sklearn.ensemble import GradientBoostingClassifier
gbc = GradientBoostingClassifier(random_state=42)
gbc.fit(X_train, y_train)
y_gbc_pred = gbc.predict(X_test)
print(accuracy_score(y_test, y_gbc_pred))
0.7083333333333334

参考:

https://www.kaggle.com

Molecular Classification of Cancer: Class Discovery and Class Prediction by Gene Expression

Science 286:531-537. (1999). Published: 1999.10.14

T.R. Golub, D.K. Slonim, P. Tamayo, C. Huard, M. Gaasenbeek, J.P. Mesirov, H. Coller, M. Loh, J.R. Downing, M.A. Caligiuri, C.D. Bloomfield, and E.S. Lander

[数据科学] 通过基因表达监测进行肿瘤预测相关推荐

  1. 数据科学作业2_房屋交易价格预测

    这是我去年选修数据科学时候的作业二,当时是肖若秀老师教的,但听说我们这届之后计科和物联信安一个难度授课了这篇文章可能也就只是自己记录帮不上学弟学妹了,但当时我上数据科学时候肖老师不签到老好了最后四个作 ...

  2. [sklearn数据科学浅尝]kaggle泰坦尼克号幸存预测问题(入全球前10%)

    问题描述 比赛地址 kaggle泰坦尼克号比赛说明 泰坦尼克号的沉没是历史上最著名的沉船之一.1912年4月15日,在她的首航中,泰坦尼克号在与冰山相撞后沉没,在2224名乘客和机组人员中造成1502 ...

  3. 敏捷数据科学pdf_敏捷数据科学数据科学可以并且应该是敏捷的

    敏捷数据科学pdf TL;DR; TL; DR; I have encountered a lot of resistance in the data science community agains ...

  4. 独家 | 2020年22个广泛使用的数据科学与机器学习工具(附链接)

    作者:RAM DEWANI 翻译:欧阳锦 校对:陈汉青 本文长度为4600字,建议阅读11分钟 本文为大家从两个方面--大数据和数据科学,介绍了本年度的22个被广泛使用的数据科学和机器学习工具.结合了 ...

  5. 解读:数据科学、机器学习和AI的区别

    当我进行以数据科学家进行自我介绍时,经常会被问道:"数据科学和机器学习有什么区别?"或者"这是不是意味着你在研究人工智能?"所以我将通过本文进行回答. 这些领域 ...

  6. sql数据透视_SQL Server中的数据科学:取消数据透视

    sql数据透视 In this article, in the series, we'll discuss understanding and preparing data by using SQL ...

  7. 揭秘京东城市时空数据引擎—JUST如何助力交通流量预测

    2014年跨年夜上海外滩灾难性踩踏事件,使得公共安全问题受到了全体社会的广泛关注.解决这一问题的很重要一项工作就是:如何实时监控和快速预测城市中每个地方的人流量.当某个地方的人流量超过给定的值或者有超 ...

  8. 图数据科学-2.使用图形数据现实世界中的科学

    当今最紧迫的数据挑战集中在控制nections,而不仅仅是将离散数据制成表格的能力.图数据科学 (GDS) 以发现和利用网络结构驱动了一系列用例,从欺诈预防和针对个性化体验和药物的针对性建议重新利用. ...

  9. 数据科学作业3_鸢尾花分类

    这是我去年选修数据科学时候的作业三,当时是肖若秀老师教的,但听说我们这届之后计科和物联信安一个难度授课了这篇文章可能也就只是自己记录帮不上学弟学妹了,但当时我上数据科学时候肖老师不签到老好了最后四个作 ...

  10. 数据科学、大数据、人工智能、机器学习的区别是什么?

    数据科学 数据科学是研究处理大量数据并为预测.规范和规范分析模型提供数据的研究.它有助于使用各种科学方法.算法.工具和流程从大量数据集中区分有用的原始数据/见解.它包括从大量数据集中挖掘.捕获.分析和 ...

最新文章

  1. 如何在 7 天内写一个程序? | 每日趣闻
  2. SD-WAN的出现对MPLS意味着什么?
  3. mysql libstdc .so.6_编译安装mysql报错 ./mysqld: /usr/lib64/libstdc++.so.6:
  4. c++ string类的常用方法_【常用类方法】Object
  5. text文字垂直居中_CSS垂直居中,你会多少种写法?
  6. 14.1.2 Checking InnoDB Availability 检查InnoDB 可用性:
  7. 软件测试——测试基础
  8. centos6.5安装sublime text 2
  9. 国家地区代号与英文名对应表
  10. java web简答题_javaweb简答题
  11. 下载安装最新kali虚拟机及切换中文方法
  12. python绘图库seaborn_Python绘图库:Seaborn 介绍
  13. 移动端怎么让底部固定_逆冬:移动端排名应该怎么做?两种匹配移动端实战排名干货分享!...
  14. 第五章 初始化和清理
  15. JQuery对联广告
  16. 6.Vue教程:http://www.jb51.net/Special/874.htm
  17. DenseNet阅读心得体会
  18. 自我激励的有效方法20个(推荐)
  19. 数据分析进阶必看干货!销售额下滑详细分析案例
  20. 亚马逊云科技 AI For Good-2022优秀方案开源分享——望楼

热门文章

  1. 使用DeepAR实现股价预测
  2. Java第七周心得体会
  3. 写给三维建模入门小白的建议
  4. 树形动态规划(树状DP)小结
  5. OAI搭建 eNB(2018-09最新版)
  6. VIOS磁盘映射关系确认
  7. 聊天记录没了怎么办?苹果手机微信聊天记录怎么恢复
  8. android免费离线讯飞语音合成
  9. CentOS Linux自动备份文件按日期备份
  10. 迈向大神之路day006