Python回归分析

2024-07-05 10:34:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用下面提到的代码运行回归分析。我遇到了一个可怕的问题:没有模块名statsmodels.api没有模块名matplotlib.pyplot文件. 如有任何建议,我们将不胜感激。你知道吗

import pandas as pd
import numpy as np
import seaborn as sns
from scipy import stats, integrate
import matplotlib.pyplot as plt
import statsmodels.api as sm

data = pd.read_csv("F:\Projects\Poli_Map\DAT_OL\MASTRTAB.csv")
# define the data/predictors as the pre-set feature names
df = pd.DataFrame(data.data, columns=data.feature_names)

# Put the target (IMR) in another DataFrame
target = pd.DataFrame(data.target, columns=["IMR"])

X = df["HH_LATR","COMM_TOILT","PWS"]
y = target["IMR"]

model = sm.OLS(y, X).fit()
predictions = model.predict(X) # make the predictions by the model

# Print out the statistics
model.summary()

plt.scatter(predictions, y, s=30, c='r', marker='+', zorder=10) #Plot graph
plt.xlabel("Independent variables")
plt.ylabel("Outcome variables")
plt.show()

Tags: 模块theimportapitargetdataframedatamodel
1条回答
网友
1楼 · 发布于 2024-07-05 10:34:45

我强烈建议你安装ANACONDA。通过这种方式,环境变量可以自动设置,您无需担心其他任何事情。有许多有用的软件包(例如numpy、sympy、scipy)与anaconda捆绑在一起。你知道吗

此外,根据个人经验,我可以告诉您,在windows上使用pip和从源代码处编译(您需要visualstudio)有时是件麻烦事。这就是水蟒被孕育的原因。你知道吗

见:https://www.anaconda.com/download/

希望这有帮助。你知道吗

相关问题 更多 >