给定时间表示中的信号图,如何绘制标记相应时间指标的线?
具体来说,给定时间索引范围为0到2.6(s)的信号图,我想绘制垂直红线,表示列表的相应时间索引[0.22058956, 0.33088437, 2.20589566],我该怎么办?
我试图tmux在我的Debian服务器上启动远程ipython笔记本.然后我在Mac OS X本地计算机上启动浏览器.开始一个长期的任务,我以后detach的tmux会话,并退出SSH连接.
但是,过了一会儿我回来并通过SSH回到服务器,我在tmux会话中发现了以下消息:
[W 19:15:52.617 NotebookApp] Notebook simplified_algo.ipynb is not trusted # The first time I left
[W 19:27:55.249 NotebookApp] WebSocket ping timeout after 119865 ms.
[I 22:09:13.696 NotebookApp] Saving file at /simplified_algo.ipynb # I then came back
[W 22:09:13.698 NotebookApp] Saving untrusted notebook simplified_algo.ipynb
[W 22:15:18.390 NotebookApp] Notebook simplified_algo.ipynb is not trusted
[I 22:17:21.426 NotebookApp] Saving file at /simplified_algo.ipynb
[W 22:17:21.428 NotebookApp] Saving untrusted notebook simplified_algo.ipynb
[I 22:19:20.954 NotebookApp] Saving …Run Code Online (Sandbox Code Playgroud) 在我的分类方案中,有几个步骤,包括:
在上述方案中要调整的主要参数是百分位数 (2.) 和 SVC (4.) 的超参数,我想通过网格搜索进行调整。
当前的解决方案构建了一个“部分”管道,包括方案中的第 3 步和第 4 步,并将方案clf = Pipeline([('normal',preprocessing.StandardScaler()),('svc',svm.SVC(class_weight='auto'))])
分解为两部分:
调整特征的百分位数以保持通过第一次网格搜索
skf = StratifiedKFold(y)
for train_ind, test_ind in skf:
X_train, X_test, y_train, y_test = X[train_ind], X[test_ind], y[train_ind], y[test_ind]
# SMOTE synthesizes the training data (we want to keep test data intact)
X_train, y_train = SMOTE(X_train, y_train)
for percentile in percentiles:
# Fisher returns the indices of the selected features specified by the parameter 'percentile'
selected_ind = Fisher(X_train, …Run Code Online (Sandbox Code Playgroud)pipeline machine-learning feature-selection scikit-learn cross-validation
我想删除重复的但保留第一个二进制向量:
x = c(0,0,1,1,0,1,0,1,1,1,0,1) # the input
y = c(0,0,1,0,1,0,1,0,1) # the desired output
Run Code Online (Sandbox Code Playgroud)
即,分别移除第一组和第三组中的一个1和两个,并保留该组中的第一组.11
我想用rle用cumsum,但尚未计算出来.任何建议将不胜感激.
基于递归特征消除和使用scikit-learn的网格搜索,我知道RFECV可以结合使用GridSearchCV以获得更好的模型参数设置,如线性SVM.
如答案所述,有两种方法:
"在RFECV上运行GridSearchCV,这将导致数据分成两次折叠(GridSearchCV内部和RFECV内部),但搜索组件数量将是有效的."
"GridSearchCV仅针对RFE,这将导致数据的单一分割,但是对RFE估计器的参数进行非常低效的扫描."
为了使我的问题清楚,我必须首先澄清RFECV:
将整个数据拆分为n个折叠.
在每个折叠中,通过仅拟合训练数据来获得特征等级rfe.
对排名进行排序并使训练数据适合SVM并在测试数据上进行测试以进行评分.这应该进行m次,每次都有减少的特征数量,其中m是假设的特征数量step=1.
在前一步骤中获得一系列得分,并且在步骤1~3已经进行n次之后,这样的序列将最后在n次折叠中平均,得到平均评分序列,表明要做的最佳特征数rfe.
以功能最数目的参数n_features_to_select在rfe装有原始整个数据.
.support_获得特色中的"赢家"; .grid_scores_得到平均得分序列.
所以我的问题是在哪里放置GridSearchCV?我猜第二种方式"在RFE上做GridSearchCV"是在第5步做GridSearchCV,它将SVM的参数设置为网格中的一个值,使其适合GridSearchCV分割的训练数据,以获得步骤中建议的功能数量4,并用其余的数据进行测试以获得分数.这样的过程在k次完成,平均得分表示网格中该值的良好性,其中k是cvGridSearchCV中的参数.但是,由于替代训练数据和网格值,所选功能可能会有所不同,如果按照我的猜测完成,则第二种方式不合理.
GridSearchCV实际上如何与RFECV结合?
我试图通过收集essentia(一个MIR库)函数来编写一个特征提取器.流程图如下:单个特征提取,池,PoolAggregator,连接以形成poolAggregator使用的整个特征列表np.concatenate
该脚本在ipython笔记本下运行良好,即使没有导入numpy.
我只是收集我从前一阶段得到的数组或浮点数,但错误信息:"NameError: global name 'numpy' is not defined"显示.
我试图将"import numpy as np"放在模块的顶部:
import numpy as np
def featureExtractor(path):
Run Code Online (Sandbox Code Playgroud)
或在功能中:
def featureExtractor(path):
import numpy as np
Run Code Online (Sandbox Code Playgroud)
或在主文件中的模块外部:
import numpy as np
from featureExtractor import featureExtractor
Run Code Online (Sandbox Code Playgroud)
这些都无法解决,请帮助我.
以下是脚本:
from essentia.standard import *
import essentia
def featureExtractor(path):
loader = MonoLoader(filename = path)
x = loader()
pool = essentia.Pool()
spectrum = Spectrum()
w = Windowing(type = 'hann')
# Create needed objects
mfcc = MFCC()
centroid = Centroid()
for frame in …Run Code Online (Sandbox Code Playgroud) 在训练和预测分类任务的进度之前,通常会分别缩放训练和测试数据。
我想嵌入上述RFECV运行 CV 测试的过程,因此我尝试了以下操作:
首先
X_scaled = preprocessing.scale(X),X整个数据集在哪里。这样做,训练和测试数据不会分开缩放,这一点不予考虑。
我尝试的另一种方法是通过:
scaling_svm = Pipeline([('scaler', preprocessing.StandardScaler()),
('svm',LinearSVC(penalty=penalty, dual=False, class_weight='auto'))])
Run Code Online (Sandbox Code Playgroud)
作为参数的参数RFECV:
rfecv = RFECV(estimator=scaling_svm, step=1, cv=StratifiedKFold(y, 7),
scoring=score, verbose=0)
Run Code Online (Sandbox Code Playgroud)
但是,我收到错误,因为RFECV需要estimator具有 attribute .coef_。我应该做什么?任何帮助,将不胜感激。
据我所知,多标签问题可以通过一对多方案来解决,为此 Scikit-learn 实现OneVsRestClassifier为分类器的包装器,例如svm.SVC. 我想知道如果我从字面上训练会有什么不同,假设我们有一个多标签问题,每个标签有 n 个类别,n 个单独的二元分类器,从而分别评估它们。
我知道这就像实现一对多而不是使用包装器的“手动”方式,但两种方式实际上不同吗?如果是这样,它们有何不同,例如执行时间或分类器的性能?
我处理的多标签分类与OneVsRestClassifier和SVC,
from sklearn.datasets import make_multilabel_classification
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV
L=3
X, y = make_multilabel_classification(n_classes=L, n_labels=2,
allow_unlabeled=True,
random_state=1, return_indicator=True)
model_to_set = OneVsRestClassifier(SVC())
parameters = {
"estimator__C": [1,2,4,8],
"estimator__kernel": ["poly","rbf"],
"estimator__degree":[1, 2, 3, 4],
}
model_tunning = GridSearchCV(model_to_set, param_grid=parameters,
scoring='f1')
model_tunning.fit(X, y)
print model_tunning.best_score_
print model_tunning.best_params_
#0.855175822314
#{'estimator__kernel': 'poly', 'estimator__C': 1, 'estimator__degree': 3}
Run Code Online (Sandbox Code Playgroud)
第一个问题
0.85代表的数字是多少?它是L分类器中的最佳分数还是平均分数?同样,这组参数是否代表L分类器中的最佳得分者?
第二个问题
基于以下事实:如果我是对的,从OneVsRestClassifier字面上L为每个标签构建分类器,可以期望访问或观察每个标签的性能.但是,在上面的例子中,如何L从GridSearchCV对象中获得分数? …
我正在使用一种简单(不一定有效)的方法来保存 Pytorch 模型。
import torch
from google.colab import files
torch.save(model, filename) # save a trained model on the VM
files.download(filename) # download the model to local
best_model = files.upload() # select the model just downloaded
best_model[filename] # access the model
Run Code Online (Sandbox Code Playgroud)
Colab 在执行最后一行期间断开连接,并且点击RECONNECTTab 总是显示ALLOCATING-> CONNECTING(失败,左下角显示“无法连接到运行时”消息)-> RECONNECT。同时,执行任何一个单元格都会给出错误消息“无法执行单元格,无法向运行时发送执行消息:[对象关闭事件]”
我知道它与最后一行有关,因为我可以成功连接到其他不执行该操作的 google 帐户。
为什么会发生?似乎已执行最后一行的 google 帐户无法再连接到运行时。
编辑:
一晚后,我可以在会话到期后重新连接 google 帐户。我只是尝试了评论中的方法,发现只有files.upload()Pytorch 模型会导致问题。上传完成后,Colab 会断开连接。
也许这个问题已被提出并得到解决,但解决方案并不适用于我.我编写了一个能够创建ggplot对象并在向量中返回它们的函数.以下是函数内部的代码,vars是我的数据列名的向量d.
plotting <- function(d){
P <- numeric(0)
vars <- names(d)[!names(d)%in%c('channel','label')]
for (var in vars){
p <- ggplot(d, aes(x=channel,y=var)) +
geom_boxplot(aes(fill=label)) + ggtitle(var)
P <- c(P,p)
}
return(list(plots=P, num=length(vars)))
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是使用上面的函数返回一个P由几个ggplots对象组成的连接列表,如下所示,这是'手动'版本正常工作:
p1 <- ggplot()+ ...
p2 <- ggplot()+ ...
p3 <- ggplot()+ ...
pdf('...')
grid.arrange(p1, p2, p3, nrow = 3)
dev.off()
Run Code Online (Sandbox Code Playgroud)
返回的目的num是在布局arg中用于后者.的grid.arrange功能.我有PLOTS返回变量:
PLOTS <- plotting(d)
pdf('...')
grid.arrange(PLOTS$plots, PLOTS$num)
dev.off()
Run Code Online (Sandbox Code Playgroud)
我收到了错误:
Error in arrangeGrob(..., as.table = as.table, clip = clip, …Run Code Online (Sandbox Code Playgroud) 我想为具有时间序列事件的数据表创建时间仓向量。这样的向量中的每个元素指示特定时隙内的度量。数据表dt如下:
dt=structure(list(
hour = c("20", "21", "21", "21", "21", "02", "02", "02", "02", "02"),
timeSlt = structure(c(6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L), .Label = c("[0,4)", "[4,8)", "[8,12)", "[12,16)", "[16,20)", "[20,24)"), class = "factor"),
play_length = c(208.67, 188.49, 58.5, 3.469, 17.92, 211.513, 193.045, 225.306, 212.715, 226.873)),
.Names = c("hour", "timeSlt", "length"),
class = c("data.table","data.frame"), row.names = c(NA, -10L))
Run Code Online (Sandbox Code Playgroud)
在此列中hour,分别timeSlt表示每天的小时数和相应的时段。timeSlt是一个因素:
dt[, timeSlt]
# [1] [20,24) [20,24) [20,24) [20,24) [20,24) [0,4) …Run Code Online (Sandbox Code Playgroud) 我试图在十次折叠交叉验证中的每一个中进行GridSearch以获得最佳超参数,它与我以前的多类分类工作一起工作得很好,但这次不是多标签工作的情况.
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
clf = OneVsRestClassifier(LinearSVC())
C_range = 10.0 ** np.arange(-2, 9)
param_grid = dict(estimator__clf__C = C_range)
clf = GridSearchCV(clf, param_grid)
clf.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
我收到错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-65-dcf9c1d2e19d> in <module>()
6
7 clf = GridSearchCV(clf, param_grid)
----> 8 clf.fit(X_train, y_train)
/usr/local/lib/python2.7/site-packages/sklearn/grid_search.pyc in fit(self, X, y)
595
596 """
--> 597 return self._fit(X, y, ParameterGrid(self.param_grid))
598
599
/usr/local/lib/python2.7/site-packages/sklearn/grid_search.pyc in _fit(self, X, y,
parameter_iterable)
357 % (len(y), n_samples))
358 y = np.asarray(y) …Run Code Online (Sandbox Code Playgroud) scikit-learn ×6
python ×5
r ×3
data.table ×1
detach ×1
duplicates ×1
function ×1
ggplot2 ×1
grid-search ×1
indexing ×1
linux ×1
matplotlib ×1
numpy ×1
pipeline ×1
pytorch ×1
ssh ×1
tmux ×1
vector ×1