我正在运行以下脚本:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.preprocessing import OneHotEncoder
dataset = pd.read_csv('data/50_Startups.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 4].values
onehotencoder = OneHotEncoder(categorical_features=3,
handle_unknown='ignore')
onehotencoder.fit(X)
Run Code Online (Sandbox Code Playgroud)
数据头看起来像: data
我有这个:
ValueError:无法将字符串转换为浮点数:'New York'
我阅读了类似问题的答案,然后打开了 scikit-learn 文档,但是如何才能看到 scikit-learn 作者没有字符串中的空格问题
我知道我可以使用LabelEncocderfromsklearn.preprocessing然后使用 OHE 并且效果很好,但在这种情况下
In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.
warnings.warn(msg, FutureWarning)
Run Code Online (Sandbox Code Playgroud)
发生按摩。
您可以使用完整的 …