【发布时间】:2017-05-15 21:48:11
【问题描述】:
我有 Dataframe df 我选择了其中的一些库,我想根据名为 Sevrice 的库将它们分为 xtrain 和 xtest。这样将带有 1 和 o 的原始数据放入 xtrain 并将 nan 放入 xtest。
Service
1
0
0
1
Nan
Nan
xtarin = df.loc[df['Service'].notnull(), ['Age','Fare', 'GSize','Deck','Class', 'Profession_title' ]]
已编辑
ytrain = df['Service'].dropna()
Xtest=df.loc[df['Service'].isnull(),['Age','Fare','GSize','Deck','Class','Profession_title']]
import pandas as pd
from sklearn.linear_model import LogisticRegression
logistic = LogisticRegression()
logistic.fit(xtrain, ytrain)
logistic.predict(xtest)
logistic.predict(xtest) 出现此错误
X has 220 features per sample; expecting 307
【问题讨论】:
标签: python pandas logistic-regression sklearn-pandas