本文整理汇总了Python中util.Util.featureNormalize方法的典型用法代码示例。如果您正苦于以下问题:Python Util.featureNormalize方法的具体用法?Python Util.featureNormalize怎么用?Python Util.featureNormalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Util
的用法示例。
在下文中一共展示了Util.featureNormalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: partExtra
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import featureNormalize [as 别名]
def partExtra():
A = scipy.misc.imread( "/Users/saburookita/Downloads/mlclass-ex7-004/mlclass-ex7/bird_small.png" )
A = A / 255.0
img_size = shape( A )
X = A.reshape( img_size[0] * img_size[1], 3 )
K = 16
max_iters = 10
initial_centroids = kMeansInitCentroids( X, K )
centroids, idx = runkMeans( X, initial_centroids, max_iters )
fig = pyplot.figure()
# axis = fig.add_subplot( 111, projection='3d' )
# axis.scatter( X[:1000, 0], X[:1000, 1], X[:1000, 2], c=idx[:1000], marker='o' )
# pyplot.show(block=True)
X_norm, mu, sigma = Util.featureNormalize( X )
U, S = pca( X_norm )
Z = projectData( X_norm, U, 2 )
axis.scatter( Z[:100, 0], Z[:100, 1], c='r', marker='o' )
pyplot.show(block=True)
示例2: part2_4
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import featureNormalize [as 别名]
def part2_4():
mat = scipy.io.loadmat( "/Users/saburookita/Downloads/mlclass-ex7-004/mlclass-ex7/ex7faces.mat" )
X = mat['X']
# displayData( X[:100, :] )
X_norm, mu, sigma = Util.featureNormalize( X )
U, S = pca( X_norm )
# displayData( U[:, :36].T )
K = 100
Z = projectData( X_norm, U, K )
X_rec = recoverData( Z, U, K )
pyplot.subplot( 1, 2, 1 )
displayData( X_norm[:100, :] )
pyplot.subplot( 1, 2, 2 )
displayData( X_rec[:100, :] )
pyplot.show( block=True )
示例3: part2_3
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import featureNormalize [as 别名]
def part2_3():
mat = scipy.io.loadmat( "/Users/saburookita/Downloads/mlclass-ex7-004/mlclass-ex7/ex7data1.mat" )
X = mat['X']
X_norm, mu, sigma = Util.featureNormalize( X )
U, S = pca( X_norm )
K = 1
Z = projectData( X_norm, U, K )
print(Z[0]) # Should be 1.481
X_rec = recoverData( Z, U, K )
for i in range( 0, shape( X_rec)[0] ):
pyplot.gca().add_line( lines.Line2D( xdata=[X_norm[i,0], X_rec[i,0]], ydata=[X_norm[i,1], X_rec[i,1]], c='g', lw=1, ls='--' ) )
pyplot.plot( X_norm[:, 0], X_norm[:, 1], 'bo' )
pyplot.plot( X_rec[:, 0], X_rec[:, 1], 'ro' )
pyplot.axis( 'equal' )
pyplot.axis( [-4, 3, -4, 3] )
pyplot.show( block=True )
示例4: part2_2
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import featureNormalize [as 别名]
def part2_2():
mat = scipy.io.loadmat( "/Users/saburookita/Downloads/mlclass-ex7-004/mlclass-ex7/ex7data1.mat" )
X = mat['X']
X_norm, mu, sigma = Util.featureNormalize( X )
U, S = pca( X_norm )
error = 1 - (sum( S[:1]) / sum( S))
print(error)
mu = mu.reshape( 1, 2)[0]
mu_1 = mu + 1.5 * S[0] * U[:, 0]
mu_2 = mu + 1.5 * S[1] * U[:, 1]
pyplot.plot( X[:, 0], X[:, 1], 'bo' )
pyplot.gca().add_line( lines.Line2D( xdata=[mu[0], mu_1[0]], ydata=[mu[1], mu_1[1]], c='r', lw=2 ) )
pyplot.gca().add_line( lines.Line2D( xdata=[mu[0], mu_2[0]], ydata=[mu[1], mu_2[1]], c='r', lw=2 ) )
pyplot.axis( [0.5, 6.5, 2, 8] )
pyplot.axis( 'equal' )
pyplot.show( block=True )