【发布时间】:2018-02-06 19:41:29
【问题描述】:
我正在关注我正在阅读的书中的这个 SVM 分类器示例代码。
我是 Python 新手,很难理解/可视化所有这些数组语法 [:,1] [:,:-1]。有人可以解释一下最后三行代码应该是什么意思/做什么。我将不胜感激。
Convert string data to numerical data
label_encoder = []
X_encoded = np.empty(X.shape)
for i,item in enumerate(X[0]):
if item.isdigit():
X_encoded[:, i] = X[:, i]
else:
label_encoder.append(preprocessing.LabelEncoder())
X_encoded[:, i] = label_encoder[-1].fit_transform(X[:, i])
X = X_encoded[:, :-1].astype(int)
y = X_encoded[:, -1].astype(int)
【问题讨论】:
-
什么是
phyton? -
@CristiArde;你可以阅读这篇文章:stackoverflow.com/questions/509211/…
-
我看了这些,我理解了,但是在这个例子中 [:, :-1] 我不知道该怎么想 thx 的建议