def generate_report(self): """ Generate a report as PDF file """ # Option pdf = FPDF() pdf.add_page() pdf.set_xy(20, 5) pdf.set_title("Naive-Bayes") pdf.accept_page_break() # Title pdf.set_font('arial', 'B', 25) pdf.cell(0, 30, 'Naive-Bayes', border=0, ln=2, align='C') # Info pdf.cell(15) pdf.set_font('arial', 'I', 14) pdf.cell(30, 2, 'Accuracy : ', border=0, ln=0, align='L') pdf.set_font('arial', '', 14) pdf.cell(50, 2, f'{self.acc}', border=0, ln=2, align='L') # Plot Report pdf.cell(10) pdf.image(self.cfg['plot_path'] + "naive-bayes-report.png", x=30, y=40, w=150, h=100, type='', link='') # Chapter pdf.set_y(140) pdf.cell(10) pdf.set_font('arial', 'B', 18) pdf.cell(0, 20, 'Confusion Matrix', border=0, ln=2, align='L') # Plot Confusion Matrix pdf.cell(0) pdf.image(self.cfg['plot_path'] + "naive-bayes-confusion-matrix.png", x=20, y=160, w=100, h=75, type='', link='') pdf.cell(10) pdf.image(self.cfg['plot_path'] + "naive-bayes-confusion-matrix-normalize.png", x=100, y=160, w=100, h=75, type='', link='') # Info -> Precision/Recall/F1 pdf.set_y(235) pdf.cell(15) pdf.set_font('arial', 'B', 12) pdf.cell(30, 7, f'{self.classes[1]} : ', border=0, ln=0, align='L') pdf.cell(50) pdf.cell(30, 7, f'{self.classes[0]} : ', border=0, ln=1, align='L') pdf.cell(20) pdf.set_font('arial', 'I', 12) pdf.cell(22, 7, f'Precision : ', border=0, ln=0, align='L') pdf.set_font('arial', '', 12) pdf.cell(60, 7, f'{self.lp}', border=0, ln=0, align='L') pdf.set_font('arial', 'I', 12) pdf.cell(22, 7, f'Precision : ', border=0, ln=0, align='L') pdf.set_font('arial', '', 12) pdf.cell(60, 7, f'{self.wp}', border=0, ln=1, align='L') pdf.cell(20) pdf.set_font('arial', 'I', 12) pdf.cell(22, 7, f'Recall : ', border=0, ln=0, align='L') pdf.set_font('arial', '', 12) pdf.cell(60, 7, f'{self.lr}', border=0, ln=0, align='L') pdf.set_font('arial', 'I', 12) pdf.cell(22, 7, f'Recall : ', border=0, ln=0, align='L') pdf.set_font('arial', '', 12) pdf.cell(60, 7, f'{self.wr}', border=0, ln=1, align='L') pdf.cell(20) pdf.set_font('arial', 'I', 12) pdf.cell(22, 7, f'F1 : ', border=0, ln=0, align='L') pdf.set_font('arial', '', 12) pdf.cell(60, 7, f'{self.lf1}', border=0, ln=0, align='L') pdf.set_font('arial', 'I', 12) pdf.cell(22, 7, f'F1 : ', border=0, ln=0, align='L') pdf.set_font('arial', '', 12) pdf.cell(60, 7, f'{self.wf1}', border=0, ln=1, align='L') pdf.add_page() pdf.set_font('arial', 'B', 18) pdf.cell(10) pdf.cell(0, 20, 'Decision Boundary', border=0, ln=2, align='L') pdf.image(self.cfg['plot_path'] + "naive-bayes-decision-boundary.png", x=20, y=30, w=180, h=120, type='', link='') pdf.output(self.cfg['info_path'] + 'naive-bayes-report.pdf', 'F')
from fpdf import FPDF # save FPDF() class into # a variable pdf pdf = FPDF() # Add a page pdf.add_page() pdf.accept_page_break() # set style and size of font # that you want in the pdf pdf.set_font("Arial", size=10) # open the text file in read mode f = open("fourier_transform_log.txt", "r") # insert the texts in pdf line_count = 1 w_img = 150 h_img = 100 h_line = 5 h_text = 10 line_inc = 1 for x in f: if 'save plot' in x: