我有一个2d numpy数组,我想以增量方式滚动每一行.我np.roll在for循环中使用这样做.但是因为我这几次打电话,我的代码真的很慢.你能帮我解决一下如何让它更快.
我的输入看起来像
array([[4,1],
[0,2]])
Run Code Online (Sandbox Code Playgroud)
我的输出看起来像
array([[4,1],
[2,0]])
Run Code Online (Sandbox Code Playgroud)
这里第0行[4,1]移动了0,第一行[0,2]移动了1.类似地,第二行将移动2,依此类推.
编辑
temp = np.zeros([dd,dd])
for i in range(min(t + 1, dd)):
temp[i,:] = np.roll(y[i,:], i, axis=0)
Run Code Online (Sandbox Code Playgroud) 在python中是否有一个函数将nd-array转换为字典,其中key是索引的元组,value是该索引处的矩阵值?
例如:
A = np.random.random([3,4,5])
Run Code Online (Sandbox Code Playgroud)
结果:
{(i,j,k): A[i,j,k]}
Run Code Online (Sandbox Code Playgroud) 在我的问题数据集中,响应变量非常偏向左侧.我试图使用h2o.randomForest()和h2o.gbm()如下的模型.在这两种情况下,我可以调整min_split_improvement并min_rows避免过度拟合.但是对于这些模型,我发现尾部观察的误差很大.我曾尝试 weights_column过对尾部观察进行过采样,并对其他观察结果进行欠采样,但这并没有帮助.
h2o.model <- h2o.gbm(x = predictors, y = response, training_frame = train,valid = valid, seed = 1,
ntrees =150, max_depth = 10, min_rows = 2, model_id = "GBM_DD", balance_classes = T, nbins = 20, stopping_metric = "MSE",
stopping_rounds = 10, min_split_improvement = 0.0005)
h2o.model <- h2o.randomForest(x = predictors, y = response, training_frame = train,valid = valid, seed = 1,ntrees =150, max_depth = 10, min_rows = 2, model_id = "DRF_DD", balance_classes …Run Code Online (Sandbox Code Playgroud) 我使用 训练了一个二元分类器模型h2o.GLM。我有大约 5-10 个功能。我想知道哪个生产速度更快?
如果我训练随机森林模型而不是 GLM,这个答案会改变吗?
我需要获得约 1 亿行的分数。我已经在分配不同观察结果的评分。
我想使用以下代码绘制猫图。
import seaborn as sns
sns.set_theme(style="ticks")
exercise = sns.load_dataset("exercise")
sns.set_style({'axes.grid': True})
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
Run Code Online (Sandbox Code Playgroud)
但这不会绘制垂直网格线。我怎样才能添加它们?
arrays ×2
h2o ×2
numpy ×2
python ×2
automl ×1
java ×1
matplotlib ×1
performance ×1
python-3.x ×1
r ×1
seaborn ×1