我“使用” Statsmodel
少于2天,并且完全不熟悉导入命令等。我想从here运行一个简单的variance_inflation_factor
,但遇到一些问题。我的代码如下:
from numpy import *
import numpy as np
import pandas as pd
from pandas import DataFrame, Series
import statsmodels.formula.api as sm
from sklearn.linear_model import LinearRegression
import scipy, scipy.stats
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
from statsmodels.api import add_constant
from numpy import linalg as LA
import statsmodels as sm
## I have been adding libraries and modules/packages with the intention of erring on the side of caution
a = df1.years_exp
b = df1.leg_totalbills
c = df1.log_diff_rgdp
d = df1.unemployment
e = df1.expendituresfor
f = df1.direct_expenditures
g = df1.indirect_expenditures
sm.variance_inflation_factor((['a', 'b', 'c', 'd', 'e', 'f']), g)
then I get the following error:
AttributeError Traceback (most recent call last)
<ipython-input-61-bb126535eadd> in <module>()
----> 1 sm.variance_inflation_factor((['a', 'b', 'c', 'd', 'e', 'f']), g)
AttributeError: module 'statsmodels' has no attribute 'variance_inflation_factor'
有人可以指导我使用正确的语法来加载和执行此模块吗?如果我发布一些源代码的链接更方便,请询问。但是,我觉得这只是一个简单的语法问题。
最佳答案
在variance_inflation_factor
中可以找到功能statsmodels.stats.outlier_influence
,如in the docs所示,因此要正确使用该功能,必须正确导入,可以选择
from statsmodels.stats import outliers_influence
# code here
outliers_influence.variance_inflation_factor((['a', 'b', 'c', 'd', 'e', 'f']), g)
关于python - Panda> Statsmodel:实现variance_inflation_factor的语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37124342/