【问题标题】:I cant find why `.read_csv` cannot make a dataframe for `.shape` to recognize我找不到为什么`.read_csv`不能为`.shape`创建一个数据框来识别
【发布时间】:2021-03-12 05:21:17
【问题描述】:

在此处遵循机器学习指南:https://www.pluralsight.com/guides/scikit-machine-learning/

运行 Python 3.8,可能有预感我需要在 IPython 中运行它,但我认为这会带来新的蠕虫。

还安装了所有导入的这些库。

我留下了%matplotlib inline 作为评论,因为我没有在 Jupyter 中运行它。

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
#%matplotlib inline

from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, classification_report

df = pd.read_csv("diabetes.csv")
print(pd.shape)
df.describe()

y = df[diabetes.csv].values
x = df.drop('diabetes', axis=1).values

X_train. X_test, y_train, y_test = train_test_split(X, y, test_size = 0.4, random_state=42)
X_train.shape, X_test.shape
((460,8), (308,8))

logreg = LogisticRegression()
logreg.fit(X_train, y_train)

y_pred = logreg.predict(X_test)

print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))

plt.show()

我在运行这段代码时遇到的错误是:

Traceback(最近一次调用最后一次): 文件“scikitmlprac.py”,第 12 行,在 打印(pd.shape) getattr 中的文件“C:\Python38\lib\site-packages\pandas_init_.py”,第 258 行 raise AttributeError(f"模块 'pandas' 没有属性 '{name}'") AttributeError:模块“熊猫”没有属性“形状”

【问题讨论】:

    标签: python python-3.x pandas matplotlib scikit-learn


    【解决方案1】:

    看来您只是在这里打错了字。 您尝试在应该是df.shape 时打印pd.shape。因此出现错误。

    【讨论】:

    • 谢谢!发现了新的错误,但现在不在问题的范围内
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    相关资源
    最近更新 更多