def build_regression_report(report_name, relevant_col_names, training_data, training_answers):
'''
Given a report_name, a list of columns to regress on, and the required training_data
create a regression model using StatsModel. Plot the residuals and a QQ plot and write
the model.summary() to the report.
report_name: The name of the pdf
relevant_col_names: a list with the columns you care about in training_data
training_data: the training set
training_answers: y, assumed to be parallel to training_data
'''
report = PdfPages(OUTPUT_DIR + report_name + '.pdf')
reduced_dataset = training_data.filter(relevant_col_names)
model, data = build_model(training_answers, reduced_dataset)
summary_text = model.summary()
with open(OUTPUT_DIR + report_name + ".txt", "w") as text_file:
text_file.write(str(summary_text))
resid_fig = plot_resid(model, data)
report.savefig(resid_fig)
report.close()
balance_preditctor.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录