本文整理匯總了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()
示例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()