我将使用sklearn中的孤立森林算法来检测乳腺癌数据集中的异常值。我正试图将该算法应用于混合数据集,但在拟合模型时出现了值错误。
以下是我的数据集: https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer/ 以下是我的代码:
以下是我的数据集: https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer/ 以下是我的代码:
from sklearn.model_selection import train_test_split
rng = np.random.RandomState(42)
X = data_cancer.drop(['Class'],axis=1)
y = data_cancer['Class']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 20)
X_outliers = rng.uniform(low=-4, high=4, size=(X.shape[0], X.shape[1]))
clf = IsolationForest()
clf.fit(X_train)
我收到的错误信息是:
ValueError: 无法将字符串转换为浮点数:'30-39'
在分类数据上是否可以使用孤立森林算法?如果可以,如何操作?
input_par = encoder.transform(['string value 1', 'string value 2'...])
但是我收到了一个错误:Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
- tagafrom array import array
另外,你的玩具示例对我来说不起作用。我收到了一个错误:TypeError: array() argument 1 or typecode must be char (string or ascii-unicode with length 1), not list
(使用Python 2)。 - user2205916values = array(data)
替换为values = np.array(data)
,就可以正常工作了。 - Mario