我正在尝试从with绘制一个plot_tree对象,但我的树图看起来不太好。我的树图看起来被压扁了:sklearnmatplotlib
下面是我的代码:
from sklearn import tree
from sklearn.model_selection import cross_val_score
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
# create tree object
model_gini_class = tree.DecisionTreeClassifier(criterion='gini')
# train the model using the training sets and check score
model_gini_class.fit(X_train, y_train)
model_gini_class.score(X_train, y_train)
# predict output
predicted_gini_class = model_gini_class.predict(X_test)
plt.figure()
tree.plot_tree(model_gini_class, filled=True)
plt.title("Decision trees on the Shakespear dataset (Gini)")
plt.show() # the tree looks squished?
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:
sklearnplot_tree对象的大小,使其看起来不被压扁吗?谢谢你,
我无法理解 python 函数到底gc.collect()是做什么的。gc.threshold该函数是否只收集那些可收集的对象,以便在达到后释放空间?或者是否gc.collect()收集对象并自动删除它收集的任何内容,以便在执行代码后立即释放空间?
我有一个A如下所示的 pytorch 张量:
A =
tensor([[ 4, 3, 3, ..., 0, 0, 0],
[ 13, 4, 13, ..., 0, 0, 0],
[707, 707, 4, ..., 0, 0, 0],
...,
[ 7, 7, 7, ..., 0, 0, 0],
[ 0, 0, 0, ..., 0, 0, 0],
[195, 195, 195, ..., 0, 0, 0]], dtype=torch.int32)
Run Code Online (Sandbox Code Playgroud)
我想:
我可以想象这样做:
zero_list = []
for j in range(A.size()[1]):
if torch.sum(A[:,j]) == 0:
zero_list = zero_list.append(j)
Run Code Online (Sandbox Code Playgroud)
识别其元素只有 0 的列,但我不确定如何从原始张量中删除这些填充有 …
对于 Pytorch 张量A:
A = tensor([1,0,0],
[0,0,0])
Run Code Online (Sandbox Code Playgroud)
有什么方法可以检查数字 1 是否是张量的一个元素A?就像是否有一个pytorch函数返回True是1是一个元素A,如果1不是一个元素,则返回False A?
谢谢,