本文整理汇总了Python中sandbox.util.Sampling.Sampling.sampleUsers方法的典型用法代码示例。如果您正苦于以下问题:Python Sampling.sampleUsers方法的具体用法?Python Sampling.sampleUsers怎么用?Python Sampling.sampleUsers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sandbox.util.Sampling.Sampling
的用法示例。
在下文中一共展示了Sampling.sampleUsers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSampleUsers
# 需要导入模块: from sandbox.util.Sampling import Sampling [as 别名]
# 或者: from sandbox.util.Sampling.Sampling import sampleUsers [as 别名]
def testSampleUsers(self):
m = 10
n = 15
r = 5
u = 0.3
w = 1-u
X, U, s, V, wv = SparseUtils.generateSparseBinaryMatrix((m,n), r, w, csarray=True, verbose=True, indsPerRow=200)
k = 50
X2, userInds = Sampling.sampleUsers(X, k)
nptst.assert_array_equal(X.toarray(), X2.toarray())
numRuns = 50
for i in range(numRuns):
m = numpy.random.randint(10, 100)
n = numpy.random.randint(10, 100)
k = numpy.random.randint(10, 100)
X, U, s, V, wv = SparseUtils.generateSparseBinaryMatrix((m,n), r, w, csarray=True, verbose=True, indsPerRow=200)
X2, userInds = Sampling.sampleUsers(X, k)
self.assertEquals(X2.shape[0], min(k, m))
self.assertTrue((X.dot(X.T)!=numpy.zeros((m, m)).all()))
self.assertTrue((X2.toarray() == X.toarray()[userInds, :]).all())
self.assertEquals(X.toarray()[userInds, :].nonzero()[0].shape[0], X2.nnz)
示例2:
# 需要导入模块: from sandbox.util.Sampling import Sampling [as 别名]
# 或者: from sandbox.util.Sampling.Sampling import sampleUsers [as 别名]
maxLocalAuc.metric = "f1"
maxLocalAuc.normalise = True
maxLocalAuc.numAucSamples = 10
maxLocalAuc.numProcesses = multiprocessing.cpu_count()
maxLocalAuc.numRecordAucSamples = 100
maxLocalAuc.numRowSamples = 30
maxLocalAuc.rate = "constant"
maxLocalAuc.recordStep = 10
maxLocalAuc.rho = 1.0
maxLocalAuc.t0 = 1.0
maxLocalAuc.t0s = 2.0**-numpy.arange(7, 12, 1)
maxLocalAuc.validationSize = 3
maxLocalAuc.validationUsers = 0
newM = X.shape[0]/4
modelSelectX, userInds = Sampling.sampleUsers(X, newM)
if saveResults:
meanObjs1, stdObjs1 = maxLocalAuc.modelSelect2(X)
meanObjs2, stdObjs2 = maxLocalAuc.modelSelect2(trainX)
meanObjs3, stdObjs3 = maxLocalAuc.modelSelect2(modelSelectX)
numpy.savez(outputFile, meanObjs1, meanObjs2, meanObjs3)
else:
data = numpy.load(outputFile)
meanObjs1, meanObjs2, meanObjs3 = data["arr_0"], data["arr_1"], data["arr_2"]
meanObjs1 = numpy.squeeze(meanObjs1)
meanObjs2 = numpy.squeeze(meanObjs2)
meanObjs3 = numpy.squeeze(meanObjs3)