简体   繁体   English

我如何 go 关于在 python 中拟合数据集? - lr.fit(x_train, y_train) 给我错误

[英]How do I go about fitting a dataset in python? - lr.fit(x_train, y_train) giving me errors

Here is my code:这是我的代码:

blood_df=pd.read_csv('blood_donation.csv')
x,y=blood_df.iloc[:,:-1], blood_df['Donated2020']
blood_df['Gender'].value_counts()
x_dummies = pd.get_dummies(x)
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x_dummies,y,random_state=0)

Then I start getting errors when I try to use the lr.fit below.然后,当我尝试使用下面的 lr.fit 时,我开始出现错误。

from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(x_train, y_train)

Here's a screengrab of the error because it's so hefty: error screengrab这是错误的屏幕截图,因为它太大了: error screengrab

Following Quang Hoang's advice in the comments, adding this worked:按照 Quang Hoang 在评论中的建议,添加此方法有效:

#imputing missing values with their mean
blood_df=blood_df.fillna(blood_df.mean())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适合 X_train 和 y_train - fitting on X_train and y_train 如何将数据集拆分为 (X_train, y_train), (X_test, y_test)? - How to split dataset into (X_train, y_train), (X_test, y_test)? 如何在 X_train、y_train、X_test、y_test 中拆分图像数据集? - How to split an image dataset in X_train, y_train, X_test, y_test? 什么是 X_train 和 y_train? - What are X_train and y_train? 如何从生成器编写数据集以替换 tensorflow 中切片中的数据集,以获取具有 X_train 和 y_train 的表格数据集 - How do I write a Dataset from generator to replace Dataset from slices in tensorflow for a tabular data set with X_train and y_train 当我们有两个 X_train 和两个 y_train 时如何拟合串联模型 - how to fit a concatenated model when we have two X_train and two y_train 如何同时对 X_train 和 y_train 应用增强 - How to simultaneously apply augmentation to X_train and y_train 如何为 LSTM keras 重塑 X_train 和 y_train - How to reshape X_train and y_train for LSTM keras 如何将数据拆分为 x_train 和 y_train - How to split data into x_train and y_train 这种python索引如何工作:'print(X_train [y_train == 0] [0])'在python中工作? - how does this sort of python indexing: 'print(X_train[y_train == 0][0])' work in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM