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


Python RealFeatures.get_feature_matrix方法代码示例

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


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

示例1: feature_function

# 需要导入模块: from modshogun import RealFeatures [as 别名]
# 或者: from modshogun.RealFeatures import get_feature_matrix [as 别名]
def feature_function():
    
    from modshogun import RealFeatures
    from modshogun import CSVFile
    import numpy as np

    #3x3 random matrix 
    feat_arr = np.random.rand(3, 3)
    
    #initialize RealFeatures from numpy array
    features = RealFeatures(feat_arr)

    #get matrix value function
    print features.get_feature_matrix(features)
    
    #get selected column of matrix
    print features.get_feature_vector(1)

    #get number of columns
    print features.get_num_features()

    #get number of rows
    print features.get_num_vectors()
    
    feats_from_csv = RealFeatures(CSVFile("csv/feature.csv"))
    print "csv is ", feats_from_csv.get_feature_matrix()
开发者ID:ysak-y,项目名称:shogun_sample,代码行数:28,代码来源:sample.py

示例2: features_dense_modular

# 需要导入模块: from modshogun import RealFeatures [as 别名]
# 或者: from modshogun.RealFeatures import get_feature_matrix [as 别名]
def features_dense_modular (A=matrixA,B=matrixB,C=matrixC):

    a=RealFeatures(A)
    b=LongIntFeatures(B)
    c=ByteFeatures(C)

# or 16bit wide ...
#feat1 = f.ShortFeatures(N.zeros((10,5),N.short))
#feat2 = f.WordFeatures(N.zeros((10,5),N.uint16))


# print(some statistics about a)

# get first feature vector and set it

    a.set_feature_vector(array([1,4,0,0,0,9], dtype=float64), 0)

# get matrices
    a_out = a.get_feature_matrix()
    b_out = b.get_feature_matrix()
    c_out = c.get_feature_matrix()

    assert(all(a_out==A))

    assert(all(b_out==B))

    assert(all(c_out==C))
    return a_out,b_out,c_out,a,b,c
开发者ID:42MachineLearning,项目名称:shogun,代码行数:30,代码来源:features_dense_modular.py

示例3: features_dense_real_modular

# 需要导入模块: from modshogun import RealFeatures [as 别名]
# 或者: from modshogun.RealFeatures import get_feature_matrix [as 别名]
def features_dense_real_modular (A=matrix):

# ... of type Real, LongInt and Byte
    a=RealFeatures(A)

# print(some statistics about a)
#print(a.get_num_vectors())
#print(a.get_num_features())

# get first feature vector and set it
#print(a.get_feature_vector(0))
    a.set_feature_vector(array([1,4,0,0,0,9], dtype=float64), 0)

# get matrix
    a_out = a.get_feature_matrix()

    assert(all(a_out==A))
    return a_out
开发者ID:42MachineLearning,项目名称:shogun,代码行数:20,代码来源:features_dense_real_modular.py

示例4: RealFeatures

# 需要导入模块: from modshogun import RealFeatures [as 别名]
# 或者: from modshogun.RealFeatures import get_feature_matrix [as 别名]
# load wine features
features = RealFeatures(CSVFile('../data/fm_wine.dat'))

print('%d vectors with %d features.' % (features.get_num_vectors(), features.get_num_features()))
print('original features mean = ' + str(numpy.mean(features, axis=1)))

# rescale the features to [0,1]
feature_rescaling = RescaleFeatures()
feature_rescaling.init(features)
features.add_preprocessor(feature_rescaling)
features.apply_preprocessor()

print('mean after rescaling = ' + str(numpy.mean(features, axis=1)))

# remove mean from data
data = features.get_feature_matrix()
data = data.T
data-= numpy.mean(data, axis=0)
print numpy.mean(data, axis=0)

fig, axarr = pyplot.subplots(1,2)
axarr[0].matshow(numpy.cov(data.T))

#### whiten data

''' this method to whiten the data didn't really work out
L = cholesky(numpy.cov(data.T))
data = solve_triangular(L, data.T, lower=True).T
'''

# covariance matrix
开发者ID:iglesias,项目名称:tests,代码行数:33,代码来源:data_whitening.py

示例5: MulticlassAccuracy

# 需要导入模块: from modshogun import RealFeatures [as 别名]
# 或者: from modshogun.RealFeatures import get_feature_matrix [as 别名]
	predicted_labels = knn.apply(test_features)
	evaluator = MulticlassAccuracy()
	acc = evaluator.evaluate(predicted_labels, test_labels)
	err = 1-acc

	return err

features_file = '../data/fm_ape_gut.txt'
labels_file = '../data/label_ape_gut.txt'

features = RealFeatures(CSVFile(features_file))
labels = MulticlassLabels(CSVFile(labels_file))

# reduce the number of features to use so that the training is faster but still
# the results of feature selection are significant
fm = features.get_feature_matrix()
features = RealFeatures(fm[:500, :])

assert(features.get_num_vectors() == labels.get_num_labels())

print('Number of examples = %d, number of features = %d.' % (features.get_num_vectors(), features.get_num_features()))

visualize_tdsne(features, labels)
lmnn = diagonal_lmnn(features, labels, max_iter=1200)

diagonal_transform = lmnn.get_linear_transform()
diagonal = numpy.diag(diagonal_transform)
print('%d out of %d elements are non-zero' % (numpy.sum(diagonal != 0), diagonal.shape[0]))

statistics = lmnn.get_statistics()
pyplot.plot(statistics.obj.get())
开发者ID:iglesias,项目名称:tests,代码行数:33,代码来源:metagenomics_ape.py


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