我正在尝试用 Python 解决 Kaggle 的泰坦尼克号。但是我在尝试拟合我的数据时出错。这是我的代码:import pandas as pdfrom sklearn import linear_modeldef clean_data(data): data["Fare"] = data["Fare"].fillna(data["Fare"].dropna().median()) data["Age"] = data["Age"].fillna(data["Age"].dropna().median()) data.loc[data["Sex"] == "male", "Sex"] = 0 data.loc[data["Sex"] == "female", "Sex"] = 1 data.loc["Embarked"] = data["Embarked"].fillna("S") data.loc[data["Embarked"] == "S", "Embarked"] = 0 data.loc[data["Embarked"] == "C", "Embarked"] = 1 data.loc[data["Embarked"] == "Q", "Embarked"] = 2train = pd.read_csv("train.csv")clean_data(train)target = train["Survived"].valuesfeatures = train[["Pclass", "Age","Sex","SibSp", "Parch"]].valuesclassifier = linear_model.LogisticRegression()classifier_ = classifier.fit(features, target) # Here is where error comes from错误是这样的:ValueError: Input contains NaN, infinity or a value too large for dtype('float64').你能帮我吗?
添加回答
举报
0/150
提交
取消