简体   繁体   English

为什么我无法使用 statsmodels api 获取 VIF

[英]Why am I not able to get the VIF using statsmodels api

I was looking at the following official documentation from statsmodels:我正在查看来自 statsmodels 的以下官方文档:

https://www.statsmodels.org/stable/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html https://www.statsmodels.org/stable/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html

But when I try to run this code on a practice dataset (statsmodels.api already imported as sm)但是当我尝试在练习数据集上运行此代码时(statsmodels.api 已经导入为 sm)

variance_inflation_factor=sm.stats.outliers_influence.variance_inflation_factor()
vif=pd.DataFrame()
vif['VIF']=[variance_inflation_factor(X_train.values,i) for i in range(X_train.shape[1])]
vif['Predictors']=X_train.columns

I get the error message: module 'statsmodels.stats.api' has no attribute 'outliers_influence我收到错误消息:模块“statsmodels.stats.api”没有属性“outliers_influence”

Can anyone tell me what is the appropriate way to get this working?谁能告诉我让这个工作的合适方法是什么?

variance_inflation_factor=sm.stats.outliers_influence.variance_inflation_factor() does not need to be defined by calling the function with no arguments. variance_inflation_factor=sm.stats.outliers_influence.variance_inflation_factor()不需要通过调用不带参数的函数来定义。 Instead, variance_inflation_factor is a function that takes two inputs.相反, variance_inflation_factor是一个接受两个输入的函数。

import pandas as pd
import numpy as np
from statsmodels.stats.outliers_influence import variance_inflation_factor

X_train = pd.DataFrame(np.random.standard_normal((1000,5)), columns=[f"x{i}" for i
in range(5)])
vif=pd.DataFrame()
vif['VIF']=[variance_inflation_factor(X_train.values,i) for i in range(X_train.shape[1])]
vif['Predictors']=X_train.columns

print(vif)

which produces产生

        VIF Predictors
0  1.002882         x0
1  1.004265         x1
2  1.001945         x2
3  1.004227         x3
4  1.003989         x4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法使用 python 使用单个输入 function 获得两个由空格分隔的 integer - why i am not able to get two integer separated by a space using single input function using python 为什么当我使用 statsmodels 进行 OLS 和使用 scikit 进行 PooledOLS 时得到相同的结果? - Why do I get the same results when I do OLS using statsmodels and PooledOLS using scikit? 我是否能够使用 JSON RPC API 通过验证器(solana)获取委托人列表? - Am I able to get a list of delegators by validator (solana) using the JSON RPC API? 为什么我不能让 BeautifulSoup 像描述的那样工作? - Why am I not able to get BeautifulSoup to work as described? 为什么我无法在图表中获得正确的日期? - Why am I not able to get proper dates in my graph? 为什么我无法通过 Pandas.count() 获得分发? - Why am I not able to get a distribution through Pandas .count()? 为什么我无法修改它? - Why am i not able to modify it? 为什么我无法使用 Beautifulsoup 抓取到此 HTML 的结尾? - Why am I not able to scrape till end of this HTML using Beautifulsoup? 为什么我无法使用蒙版图像提取对象? - Why I am not able to extract the object using the masked image? 为什么我无法使用 Selenium 打开 google.com? - Why am I not able to open google.com using Selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM