我有以下帶有內部函式的代碼,但是每當我使用引數運行它時,它都不會回傳“sorted_rsq”。
def improve_model (formula, covariates, data):
"""Returns a new formula which has a new added covariate which is the best single covariate in terms of R^2"""
#Get the formulas given all covariates
olsformulas = extend_model(formula,covariates)
#Using all formulas to calculate R^2 for each
def ols(formula, data):
"""Calculates the R^2 of a given formula."""
all = {}
for formula in olsformulas:
fit = smf.ols(formula,data).fit().rsquared
all[formula] = fit
sorted_rsq = sorted(all.items(), key = lambda x: x[1], reverse = True)
return sorted_rsq[0]
ols(formula,data)
只是給我空白結果。任何人都可以幫助我代碼有什么問題嗎?
uj5u.com熱心網友回復:
替換ols(formula,data)與return ols(formula,data)在外部函式的末尾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/363091.html
