【问题标题】:I'm getting the type error on writing the following code我在编写以下代码时遇到类型错误
【发布时间】:2021-06-29 20:39:52
【问题描述】:

Jupyter Notebook 上的代码:

import pandas as pd
import matplotlib as plt
%matplotlib inline
import numpy as np

data = pd.read_csv("E:Datascience\Bivariate\Titanic.csv")

data.head()

data.shape


data['Survived'].value_counts()

data=pd.get_dummies(data)

data.fillna(0,inplace=True)

data.shape

train=data[0:699]


test=data[700:890]


x_train=train.drop('Survived',axis=1)

y_train = train['Survived']

x_test=test.drop('Survived',axis=1)



true_p=test['Survived']

from sklearn.linear_model import LogisticRegression

logreg=LogisticRegression

logreg.fit(x_train,y_train)

错误:

Error - ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-48-cdb43f357e36> in <module>
----> 1 logreg.fit(x_train,y_train)

TypeError: fit() missing 1 required positional argument: 'y'

【问题讨论】:

  • logreg=LogisticRegression改成logreg=LogisticRegression(),解决了吗?

标签: python pandas jupyter typeerror


【解决方案1】:

使用这个

logreg=LogisticRegression()

而不是

 logreg=LogisticRegression

这将解决您的问题。

你可以参考这个tutorial

【讨论】:

    猜你喜欢
    • 2012-05-30
    • 2012-10-18
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 2023-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多