当前位置: 首页>>代码示例>>Python>>正文


Python StandardScaler.transpose方法代码示例

本文整理汇总了Python中sklearn.preprocessing.StandardScaler.transpose方法的典型用法代码示例。如果您正苦于以下问题:Python StandardScaler.transpose方法的具体用法?Python StandardScaler.transpose怎么用?Python StandardScaler.transpose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.preprocessing.StandardScaler的用法示例。


在下文中一共展示了StandardScaler.transpose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: len

# 需要导入模块: from sklearn.preprocessing import StandardScaler [as 别名]
# 或者: from sklearn.preprocessing.StandardScaler import transpose [as 别名]
csvfile=open('GSE5325_series_matrix.csv','rb')
D=csv.reader(csvfile, delimiter=' ', quotechar='|')
sample=[]
for line in D:
    sample.append(','.join(line))
csvfile.close() 
sample=sample[90:27738]

#filter out genes with NULL and imcomplete expression data
String=[line.split() for line in sample]#caution: CCNB2 is gene number 11396, and XBP1 is number 4404
RtlenStr=[line for line in String if len(line)==106 ] #string with right number of samples
ValStr=[line[1:] for line in RtlenStr if 'NULL' not in line] #filter out those with 'NULL' data
Y=np.array([float(item) for line in ValStr for item in line])
X=Y.reshape(len(ValStr),len(Y)/len(ValStr))
X_std = StandardScaler().fit_transform(X)
X_std=X_std.transpose()
mean_vecX = np.mean(X_std, axis=0)
cov_mat = (X_std - mean_vecX).transpose().dot((X_std - mean_vecX)) / (X_std.shape[0]-1)
print('NumPy covariance matrix: \n%s' %cov_mat)



pca = PCA()
I = np.identity(X_std.transpose().shape[0])
b = pca.fit(X_std).transform(I)
U=b.transpose()
Z=matmult(U,X_std.transpose())
W=np.array([float(item) for line in Z for item in line])
V=W.reshape(len(Z),len(W)/len(Z))
Z_std = StandardScaler().fit_transform(V)
Z_std=Z_std.transpose()
开发者ID:chinadd,项目名称:PCA,代码行数:33,代码来源:part4.py

示例2: range

# 需要导入模块: from sklearn.preprocessing import StandardScaler [as 别名]
# 或者: from sklearn.preprocessing.StandardScaler import transpose [as 别名]
##--------Only use genes with at 25 reads in all samples
goodcount = goodcount[goodcount.apply(sum, axis = 1) > 25]

##--------Remove genes that has corelation coefficient more than 90% tile with less than 5 other genes 
cor = np.corrcoef(goodcount)
percent = np.percentile(cor, 90)
for i in range(0, len(cor)):
    remove_gene = []
    if sum(cor[i, :] > percent) < 5:
        remove_gene.append(i)
goodcount = goodcount.drop(goodcount.index[remove_gene])

##--------PCA
gc_std = StandardScaler().fit_transform(goodcount)
pca = PCA(n_components=3)
gc_pca = pca.fit_transform(gc_std.transpose())

fil = gc_pca[:, 1] > 60  
plt.plot(gc_pca[-fil][:, 0], gc_pca[-fil][:, 1], 'o', markersize=3, color='blue', alpha=0.5)
#(x, y, label) = (gc_pca[0,0], gc_pca[0,1], goodcount.columns.values[0])
#(x, y, label) = (gc_pca[2,0], gc_pca[2,1], goodcount.columns.values[1])
#plt.annotate(label, xy=(x,y), xytext=(x,y))
for (x, y, label) in zip(gc_pca[fil][:,0], gc_pca[fil][:,1], goodcount.columns.values[fil]):
    plt.annotate(label, xy=(x, y), xytext = (x, y), \
    xycoords = 'data', textcoords = 'data')
plt.xlabel('pc_1')
plt.ylabel('pc_2')
plt.legend()
plt.title('Single cell PCA plot')
plt.savefig('%sImages/first_pca.pdf' % dirname)
plt.show()
开发者ID:hft7h11,项目名称:Scripts,代码行数:33,代码来源:Analysis_for_Tarik.py


注:本文中的sklearn.preprocessing.StandardScaler.transpose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。