parser.add_argument("iter", type=int, help="the number of iterations") parser.add_argument("-t", "--testSize", type=float, help="test size", default=0.5) args = parser.parse_args() rank = args.rank iter = args.iter inputFile = args.inputFile exptID = args.exptID patientSet = args.patientSet outsql = "results/pred-model-{0}-{1}.sql".format(exptID, rank) print "Using Rank {0} and iterations {1} and test size {2}".format(rank, iter, args.testSize) ## Load information to run the tests X = sptensor.loadTensor(inputFile.format("data")) tensorInfo = shelve.open(inputFile.format("info"), "r") Y = tensorInfo["class"] XAxis = tensorInfo["axis"] tensorInfo.close() Y = np.array(Y, dtype=int) pm = predictionModel.predictionModel(X, XAxis, Y, rank, testSize=args.testSize, outerIter=iter) output = pm.evaluatePrediction() output = np.column_stack((np.repeat(exptID, output.shape[0]), output)) outputFile = "results/pred-model-{0}-{1}.csv".format(exptID, rank) np.savetxt(outputFile, output, delimiter=",") sqlOut = file(outsql, "w") sqlOut.write("load client from /home/joyceho/workspace/tensor/{0} of del modified by coldel, insert into joyceho.predictive_results;\n".format(outputFile)) sqlOut.write("insert into joyceho.predictive_models values({0}, {1}, \'{2}\',{3}, {4});\n".format(exptID, rank, patientSet, iter, 10)) sqlOut.close()
matrixSize = np.array([3412, 247, 816]) #print matrixValue re = pd.read_csv(data_dir + 'vadationResult_3412.csv') #print re Y = np.array(re.ix[:, 'InHosLabel']) #print Y X = sptensor.sptensor(matrixIndex, matrixValue, matrixSize) #print X.subs #print X.subs.shape ''' demoX=pd.read_csv(data_notebook+'demoF.csv') demoX.index=demoX.ix[:,0] demoX=np.array(demoX.ix[:,1:]) #demoX=demoX[:,1:] print(demoX.shape) #print demoX[:3] ''' goNum = [10, 30, 50, 80, 100, 125, 150, 180, 200] for i in range(len(goNum)): phennum = goNum[i] pm = predictionModel.predictionModel(X, X.subs, Y, phennum) pm.evaluatePredictionAUC_1(str(phennum) + 'phens_Uapr_100outIter') csvfile = file(data_dir + 'probablity', 'wb') writer = csv.writer(csvfile) csvfile.close()
import tensor import sptensor import numpy as np import ktensor import predictionModel subs = np.array([[0,3,1], [1,0,1], [1,2,1], [1,3,1], [2,4,0], [3,0,0],[4,4,1]]); vals = np.array([[1],[1],[1],[1],[4],[3],[2]]); siz = np.array([5,5,2]) # 5x5x2 tensor np.random.seed(0) X = sptensor.sptensor(subs, vals, siz) Y = np.random.randint(2, size=5) pm = predictionModel.predictionModel(X, Y, 2) pm.evaluatePrediction()
testXSize = np.array([1024, 247, 816]) testTensor = sptensor.sptensor(testXIndex, testXValue, testXSize) trainRe = pd.read_csv(data_dir + 'TrainResult_2387.csv') trainY = trainRe.ix[:, -1].as_matrix() trainY[trainY == 0] = -1 print trainY.sum() testRe = pd.read_csv(data_dir + 'TestResult_1024.csv') testY = testRe.ix[:, -1].as_matrix() testY[testY == 0] = -1 print testY.sum() #goNum=[30,50,80,100,120,150,180,200] goNum = [10, 30, 50, 80, 100, 125, 150, 180, 200] for i in range(len(goNum)): phennum = goNum[i] pm = predictionModel.predictionModel(trainTensor, trainTensor.subs, trainY, phennum) if i == 0: first = True else: first = False pm.evaluatePredictionAUC_4( str(phennum) + 'phens_ttapr_100outIter', trainTensor, trainY, testTensor, testY) csvfile = file(data_dir + 'probablity', 'wb') writer = csv.writer(csvfile) csvfile.close()
import tensor import sptensor import numpy as np import ktensor import predictionModel subs = np.array([[0, 3, 1], [1, 0, 1], [1, 2, 1], [1, 3, 1], [2, 4, 0], [3, 0, 0], [4, 4, 1]]) vals = np.array([[1], [1], [1], [1], [4], [3], [2]]) siz = np.array([5, 5, 2]) # 5x5x2 tensor np.random.seed(0) X = sptensor.sptensor(subs, vals, siz) Y = np.random.randint(2, size=5) pm = predictionModel.predictionModel(X, Y, 2) pm.evaluatePrediction()