我试图用下面提到的代码进行回归分析。我遇到了ImportError:没有一个模块名为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()发布于 2017-10-30 13:07:46
我强烈建议您安装ANACONDA。这样,环境变量就会自动设置,您就不需要担心其他任何事情了。有许多有用的软件包(例如,矮胖,同情,枕木),这些包都是与蟒蛇捆绑在一起的。
此外,根据我个人的经验,我可以告诉你,在windows上使用pip并从源代码编译(您需要visual )有时会让人头疼。这就是为什么ANACONDA被孕育了。
请参阅:https://www.anaconda.com/download/
希望这能有所帮助。
https://stackoverflow.com/questions/47015838
复制相似问题