摘要:来自sklearn。CompositionimportDictionaryLearning#数据预处理字典学习字典学习模型defest_DictionaryLearning():X=[[1,2,3,4,5],[6,7,8,9,10],[10,9,8,7,6,],[5,4,3,2,1]]print(“beforetransform:”,X)dct=字典
from sklearn.decomposition import DictionaryLearning
#数据预处理字典学习DictionaryLearning模型
def test_DictionaryLearning():
X=[[1,2,3,4,5],
[6,7,8,9,10],
[10,9,8,7,6,],
[5,4,3,2,1]]
print("before transform:",X)
dct=DictionaryLearning(n_components=3)
dct.fit(X)
print("components is :",dct.components_)
print("after transform:",dct.transform(X))
# 调用 test_DictionaryLearning
test_DictionaryLearning()
from sklearn.decomposition import MiniBatchDictionaryLearning
#数据预处理字典学习MiniBatchDictionaryLearning模型
def test_MiniBatchDictionaryLearning():
X=[[1,2,3,4,5],
[6,7,8,9,10],
[10,9,8,7,6,],
[5,4,3,2,1]]
print("before transform:",X)
dct=DictionaryLearning(n_components=3)
dct.fit(X)
print("components is :",dct.components_)
print("after transform:",dct.transform(X))
# 调用 test_MiniBatchDictionaryLearning
test_MiniBatchDictionaryLearning()