在我的逻辑回归代码期间遇到的值错误



我在转换逻辑模型时收到与输入形状相关的值错误

titanic_data = pd.read_csv("E:\Python\CSV\train.csv")
titanic_data.drop('Cabin', axis=1, inplace=True)
titanic_data.dropna(inplace=True)
#print(titanic_data.head(10))
new_sex = pd.get_dummies(titanic_data['Sex'],drop_first=True)
new_embarked = pd.get_dummies(titanic_data['Embarked'],drop_first=True)
new_pcl = pd.get_dummies(titanic_data['Pclass'],drop_first=True)
titanic_data = pd.concat([titanic_data,new_sex,new_embarked,new_pcl],axis=1)
titanic_data.drop(['PassengerId','Pclass','Name','Sex','Ticket','Embarked','Age','Fare'],axis=1,inplace=True)
X = titanic_data.drop(['Survived'],axis=1)
y = titanic_data['Survived']
print(X)
print(y)
X_train, y_train, X_test, y_test = train_test_split(X,y,test_size=0.3, random_state=1)
logreg = LogisticRegression()
logreg.fit(X_train,y_train)

错误

raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (214, 7)

您将拆分数据解压缩到错误的变量中,顺序应如下所示:

X_train, X_test, y_train, y_test = train_test_split(...)

https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html

相关内容

  • 没有找到相关文章

最新更新