Python 发行转换
作为数据科学家,我是Python的初学者。我正在做一个项目,但我不能超过这个阶段。 ValueError:无法将字符串转换为浮点:“506和谐项次” 这是我的代码:Python 发行转换,python,scikit-learn,Python,Scikit Learn,作为数据科学家,我是Python的初学者。我正在做一个项目,但我不能超过这个阶段。 ValueError:无法将字符串转换为浮点:“506和谐项次” 这是我的代码: from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import mean_absolute_error from sklearn.pre
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error
from sklearn.preprocessing import LabelEncoder
from sklearn.ensemble import RandomForestRegressor
## Add these lines to turn off the warnings
import warnings
warnings.filterwarnings("ignore")
# Segragate dataset into train and test
train = data.drop(['price', 'date'], axis=1)
test = data['price']
X_train, X_test, y_train, y_test = train_test_split(train, test, test_size=0.3, random_state=2)
regr = LinearRegression()
regr.fit(X_train, y_train)
ValueError: could not convert string to float: '506 Harmony Ln'
链接到数据:
谢谢在拟合模型之前,所有字符串值都需要转换为数字,即1和0,然后才能执行。创建虚拟变量请参阅my以创建虚拟变量。在拟合模型之前,所有字符串值都需要转换为数字,即1和0,然后才能执行。创建虚拟变量请参阅my以创建虚拟变量。