本文整理汇总了Python中sklearn.decomposition.NMF.inverse_transform方法的典型用法代码示例。如果您正苦于以下问题:Python NMF.inverse_transform方法的具体用法?Python NMF.inverse_transform怎么用?Python NMF.inverse_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.NMF
的用法示例。
在下文中一共展示了NMF.inverse_transform方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nmf_inverse_transform
# 需要导入模块: from sklearn.decomposition import NMF [as 别名]
# 或者: from sklearn.decomposition.NMF import inverse_transform [as 别名]
def test_nmf_inverse_transform(solver):
# Test that NMF.inverse_transform returns close values
random_state = np.random.RandomState(0)
A = np.abs(random_state.randn(6, 4))
m = NMF(solver=solver, n_components=4, init='random', random_state=0,
max_iter=1000)
ft = m.fit_transform(A)
A_new = m.inverse_transform(ft)
assert_array_almost_equal(A, A_new, decimal=2)
示例2: test_nmf_inverse_transform
# 需要导入模块: from sklearn.decomposition import NMF [as 别名]
# 或者: from sklearn.decomposition.NMF import inverse_transform [as 别名]
def test_nmf_inverse_transform():
# Test that NMF.inverse_transform returns close values
random_state = np.random.RandomState(0)
A = np.abs(random_state.randn(6, 4))
m = NMF(n_components=4, init="random", random_state=0)
m.fit_transform(A)
t = m.transform(A)
A_new = m.inverse_transform(t)
assert_array_almost_equal(A, A_new, decimal=2)
示例3: main
# 需要导入模块: from sklearn.decomposition import NMF [as 别名]
# 或者: from sklearn.decomposition.NMF import inverse_transform [as 别名]
def main():
train_data, train_length = get_train_data()
test_data, test_length, width, height = get_test_data()
model = NMF(n_components=5, init='random', random_state=0)
W = model.fit_transform(train_data)
H = model.components_
compressed_images = model.transform(test_data)
output_images = model.inverse_transform(compressed_images)
output_length= len(output_images)
rgb_length = int(output_length/3)
reconstruct_subimages = np.zeros([height*width, 25, 3], dtype=np.float32)
for channels in range(3):
reconstruct_subimages[:, :, int(channels)] = output_images[(rgb_length*channels):(rgb_length*(channels+1)),:]
all_image_rec = np.zeros([25,height,width,3], dtype=np.float32)
for x in range(width):
for y in range(height):
all_image_rec[:,y,x,:] = reconstruct_subimages[y * width + x,:]*255
for numbers in range(25):
all_image_rec[numbers, :, :, :] = cv2.cvtColor(all_image_rec[numbers, :, :, :], cv2.COLOR_BGR2RGB)
cv2.imwrite("./Reconstruct/" + str(numbers+1) + "_" + "NMF" + ".png", all_image_rec[numbers, :, :, :])
示例4: interp_shots
# 需要导入模块: from sklearn.decomposition import NMF [as 别名]
# 或者: from sklearn.decomposition.NMF import inverse_transform [as 别名]
new_cpsi = np.linspace(np.max( (exp_cpsi2.min(),sim_cpsi2.min()) )+0.05,
np.min((exp_cpsi2.max(), sim_cpsi2.max()))-0.05,
interp_num_phi,endpoint=False )
interp_cpsi[qidx] = new_cpsi
interp_X = interp_shots(norm_X2, interp_num_phi, sim_cpsi2, new_cpsi)
interp_pro = interp_shots(norm_GDPpro2, interp_num_phi, exp_cpsi2, new_cpsi)
interp_buf = interp_shots(norm_buf2, interp_num_phi, exp_cpsi2, new_cpsi)
# transform and inverse transform
model = NMF(n_components=10,solver='cd')
W=model.fit_transform(interp_X)
H=model.components_
new_buf = model.transform(interp_buf)
new_pro = model.transform(interp_pro)
inverse_diff = model.inverse_transform(new_pro-new_buf)
# average and error estimate
pro[qidx] = inverse_diff.mean(0)
err[qidx] = inverse_diff.std(0)/np.sqrt(inverse_diff.shape[0])
grp.create_dataset('ave_cor',data=pro)
grp.create_dataset('err',data=err)
grp.create_dataset('num_shots',data=inverse_diff.shape[0])
grp.create_dataset('interp_cpsi', data = interp_cpsi)
grp.create_dataset('nnmf_n_components', data = model.n_components)