我有一个数据集,我想在这些数据上训练我的模型.在训练之后,我需要知道SVM分类器分类中主要贡献者的特征.
对森林算法有一些称为特征重要性的东西,有什么类似的吗?
我正在运行以下代码
import torch
from __future__ import print_function
x = torch.empty(5, 3)
print(x)
Run Code Online (Sandbox Code Playgroud)
在CPU模式下的Ubuntu机器上,它给我跟随错误,原因是什么以及如何修复
x = torch.empty(5, 3)
----> print(x)
/usr/local/lib/python3.6/dist-packages/torch/tensor.py in __repr__(self)
55 # characters to replace unicode characters with.
56 if sys.version_info > (3,):
---> 57 return torch._tensor_str._str(self)
58 else:
59 if hasattr(sys.stdout, 'encoding'):
/usr/local/lib/python3.6/dist-packages/torch/_tensor_str.py in _str(self)
216 suffix = ', dtype=' + str(self.dtype) + suffix
217
--> 218 fmt, scale, sz = _number_format(self)
219 if scale != 1:
220 prefix = prefix + SCALE_FORMAT.format(scale) + ' ' * …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Sanic上执行文件上传,但它无法正常工作,烧瓶的正常语法似乎不适用于sanic.
我甚至无法访问文件名或save方法来将上传的文件保存到给定目录.
我正在使用以下代码进行特征重要性计算。
from matplotlib import pyplot as plt
from sklearn import svm
def features_importances(coef, names):
imp = coef
imp,names = zip(*sorted(zip(imp,names)))
plt.barh(range(len(names)), imp, align='center')
plt.yticks(range(len(names)), names)
plt.show()
features_names = ['input1', 'input2']
svm = svm.SVC(kernel='linear')
svm.fit(X, Y)
feature_importances(svm.coef_, features_names)
Run Code Online (Sandbox Code Playgroud)
我如何能够计算非线性内核的特征重要性,这在给定的示例中没有给出预期的结果。
我已经在KNN分类算法上训练了模型,并且获得了约97%的准确度。但是,后来我发现我错过了对数据进行归一化的工作,对数据进行了归一化并重新训练了模型,现在我的准确率仅为87%。可能是什么原因?我应该坚持使用未规范化的数据,还是应该切换到规范化版本。
如何在 Pytorch 中对以下全连接网络应用 dropout:
class NetworkRelu(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(784,128)
self.fc2 = nn.Linear(128,64)
self.fc3 = nn.Linear(64,10)
def forward(self,x):
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.softmax(self.fc3(x),dim=1)
return x
Run Code Online (Sandbox Code Playgroud)