我试图从信号中分离出背景,因为我们知道,数量x^2 - y^2是背景和信号不同的物理原因。如果我提供x和y作为输入变量,BDT很难弄清楚如何实现分离。BDT不能做正方形吗?
发布于 2018-09-13 03:33:52
不能,二进制决策树不能取输入特征的平方。给定输入特征x,y,它将尝试通过沿垂直线和水平线细分x,y平面来近似期望的函数。让我们来看一个例子:我将一个决策树分类器拟合到一个正方形的点网格上,并绘制决策边界。
from sklearn.tree import DecisionTreeClassifier
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-5.5, 5.5, 1)
y = np.arange(-5.0, 6.0, 1)
xx, yy = np.meshgrid(x,y)
#the function we want to learn:
target = xx.ravel()**2 - yy.ravel()**2 > 0
data = np.c_[xx.ravel(), yy.ravel()]
#Fit a decision tree:
clf = DecisionTreeClassifier()
clf.fit(data, target)
#Plot the decision boundary:
xxplot, yyplot = np.meshgrid(np.arange(-7, 7, 0.1),
np.arange(-7, 7, 0.1))
Z = clf.predict(np.c_[xxplot.ravel(), yyplot.ravel()])
# Put the result into a color plot
Z = Z.reshape(xxplot.shape)
plt.contourf(xxplot, yyplot, Z, cmap=plt.cm.hot)
# Plot also the training points
plt.scatter(xx.ravel(), yy.ravel(), c=target, cmap=plt.cm.flag)
plt.xlabel("x")
plt.ylabel("y")
plt.title("Decision boundary for a binary decision tree learning a function x**2 - y**2 > 0")
plt.show()

在这里,您可以看到决策树可以学习的边界类型:分段矩形。它们不会很好地逼近你的函数,特别是在训练点很少的地区。由于您知道x^2 - y^2是决定答案的数量,因此您可以将其作为新功能添加,而不是尝试学习它。
https://stackoverflow.com/questions/52296164
复制相似问题