def calculate(self): self.allPredicts = np.zeros((4, self.testSize)) bias = Bias(self.trainData, self.testData) bias.calculateBias() answers, predicts = bias.predict() self.biasClass = bias self.allPredicts[0, :] = predicts #print("Bias: %f" % evaluationRMSE(answers, predicts)) similarity = Similarity(self.trainData, self.testData) similarity.calculateBias() similarity.calcSimiMatrix() answers, predicts = similarity.predict() self.similarityClass = similarity self.allPredicts[1, :] = predicts #print("Similarity: %f" % evaluationRMSE(answers, predicts)) svd = SVD(self.trainData, self.testData) svd.generaterMat() svd.calcSVD() answers, predicts = svd.predict() self.svdClass = svd self.allPredicts[2, :] = predicts #print("SVD: %f" % evaluationRMSE(answers, predicts)) matFactory = MatFactory(self.trainData, self.testData) matFactory.train(10, 11) answers, predicts = matFactory.predict() self.matFactoryClass = matFactory self.allPredicts[3, :] = predicts #print("MatFactory: %f" % evaluationRMSE(answers, predicts)) pickleFile = open(predictsFile, 'wb') pickle.dump(self.allPredicts, pickleFile)
def calAll(self): self.errs = [0] * 5 bias = Bias(self.data, self.test) bias.calculateBias() answers, predicts = bias.predict() err = evaluationRMSE(answers, predicts) self.errs[0] = err print("Bias: %f" % err) similarity = Similarity(self.data, self.test) similarity.calculateBias() similarity.calcSimiMatrix() answers, predicts = similarity.predict() err = evaluationRMSE(answers, predicts) self.errs[1] = err print("Similarity: %f" % err) svd = SVD(self.data, self.test) svd.generaterMat() svd.calcSVD() answers, predicts = svd.predict() err = evaluationRMSE(answers, predicts) self.errs[2] = err print("SVD: %f" % err) matFactory = MatFactory(self.data, self.test) matFactory.train(20, 35) answers, predicts = matFactory.predict() err = evaluationRMSE(answers, predicts) self.errs[3] = err print("MatFactory: %f" % evaluationRMSE(answers, predicts)) combination = Combination(self.data) combination.separateData() combination.calculate() combination.train(alpha=0.01, iter=10000) answers, predicts = combination.predict(self.test) err = evaluationRMSE(answers, predicts) self.errs[4] = err print("Combination: %f" % err) return self.errs
def calAll(self): self.errs = [0] * 5 bias = Bias(self.data, self.test) bias.calculateBias() answers, predicts = bias.predict() err = evaluationRMSE(answers, predicts) self.errs[0] = err print("Bias: %f" % err) similarity = Similarity(self.data, self.test) similarity.calculateBias() similarity.calcSimiMatrix() answers, predicts = similarity.predict() err = evaluationRMSE(answers, predicts) self.errs[1] = err print("Similarity: %f" % err) svd = SVD(self.data, self.test) svd.generaterMat() svd.calcSVD() answers, predicts = svd.predict() err = evaluationRMSE(answers, predicts) self.errs[2] = err print("SVD: %f" % err) matFactory = MatFactory(self.data, self.test) matFactory.train(20, 35) answers, predicts = matFactory.predict() err = evaluationRMSE(answers, predicts) self.errs[3] = err print("MatFactory: %f" % evaluationRMSE(answers, predicts)) combination = Combination(self.data) combination.separateData() combination.calculate() combination.train(alpha = 0.01, iter = 10000) answers, predicts = combination.predict(self.test) err = evaluationRMSE(answers, predicts) self.errs[4] = err print("Combination: %f" % err) return self.errs