有关NN和其他机器学习算法的数据规范化(不确定这是否是正确的术语)的最佳实践是什么?我的意思是你如何向NN /算法表示数据.
例如,您如何表示商店代码?商店555不大于或小于554,它只是一个分类.NNs/algo模型是否只是自己过滤掉或者你是否需要刺激它们进行分类而不是数学上的区分?
感谢您在指导我获取适当信息方面的任何帮助.我显然是新手.
编辑:感谢大家的答案.我一直在挖掘相当多的数据挖掘书籍,虽然我发现有一些关于数据预处理的话题花了一两章,但我对它如何最完全地掩盖它有点惊讶.再次感谢.
我正在尝试实现一个层(通过lambda层),它执行以下numpy过程:
def func(x, n):
return np.concatenate((x[:, :n], np.tile(x[:, n:].mean(axis = 0), (x.shape[0], 1))), axis = 1)
Run Code Online (Sandbox Code Playgroud)
我被卡住了,因为我不知道如何获得x的第一个维度的大小(这是批量大小).后端函数int_shape(x)返回(None, ...).
所以,如果我知道batch_size,相应的Keras过程将是:
def func(x, n):
return K.concatenate([x[:, :n], K.tile(K.mean(x[:, n:], axis=0), [batch_size, 1])], axis = 1)
Run Code Online (Sandbox Code Playgroud) 我正在尝试在R中实现一个简单的梯度增强算法用于回归.这是我到目前为止所提出的,但错误不是像我预期的那样平稳.有什么建议?
data("OrchardSprays")
niter <- 10
learn <- 0.05
y <- OrchardSprays$decrease
yhat <- rep(0,nrow(OrchardSprays))
weight <- rep(1,nrow(OrchardSprays))
loss <- function(y,yhat) (y - yhat)^2
for (i in seq(niter))
{
model <- lm(decrease~.,weights=weight,data=OrchardSprays)
yhat <- yhat + weight * (predict(model) - yhat) / i
error <- mean(loss(y,yhat))
weight <- weight + learn * (loss(y,yhat) - error) / error
cat(i,"error:",error,"\n")
}
Run Code Online (Sandbox Code Playgroud)
输出:
1 error: 319.5881
2 error: 318.6175
3 error: 317.9368
4 error: 317.6112
5 error: 317.6369
6 error: 317.9772
7 error: 318.5833 …Run Code Online (Sandbox Code Playgroud) 我的dfDataFrame索引如下所示:
Com_Lag_01
Com_Lag_02
Com_Lag_03
Com_Lag_04
Com_Lag_05
Com_Lag_06
Com_Lag_07
Com_Lag_08
Com_Lag_09
Com_Lag_10
Com_Lag_101
Com_Lag_102
Com_Lag_103
...
Com_Lag_11
Com_Lag_111
Com_Lag_112
Com_Lag_113
Com_Lag_114
...
Com_Lag_12
Com_Lag_120
...
Com_Lag_13
Com_Lag_14
Com_Lag_15
Run Code Online (Sandbox Code Playgroud)
我想,这样的数字从去梳理这个指数Com_Lag_1来Com_Lag_120.如果我使用,df.sort_index()我会得到与上面相同的东西.有关如何正确排序此索引的任何建议?
我试图训练ActionValueNetwork一个简单的XOR函数,但结果看起来像随机.
""" Reinforcement Learning to learn xor function
"""
# generic import
import numpy as np
import random
# pybrain import
from pybrain.rl.explorers import EpsilonGreedyExplorer
from pybrain.rl.agents import LearningAgent
from pybrain.rl.learners.valuebased import ActionValueNetwork, NFQ
# The parameters of your algorithm
av_network = ActionValueNetwork(2, 2) # 2 dimensions in input, 2 actions possible (1 or 0)
learner = NFQ()
learner._setExplorer(EpsilonGreedyExplorer(0.0)) # No exploration
agent = LearningAgent(av_network, learner)
# The training
for _ in xrange(1,25): # we iterate 25 times …Run Code Online (Sandbox Code Playgroud) 我正在使用HCRF库进行序列预测任务.为了学习模型参数,我使用LBFGS,尽管有使用CG和BFGS的选项.
我注意到收敛需要很长时间.我已经将最大迭代次数(当前)设置为5000.如果我对HCRF库的解释是正确的,那么从迭代到迭代的估计值的变化会变得更小.但是,该程序似乎不会在少于5000次迭代中终止,而且它实际上只需要很长时间.
如果我将最大迭代次数设置为500,那么在第500次迭代时,结果如下所示:
Iteration 500
fx = 465.359
xnorm 38.0831, gnorm = 46.3165, step = 1line search = 1
Run Code Online (Sandbox Code Playgroud)
它以此消息终止:
L-BFGS optimization terminated with status code = -997
fx = 465.359
Run Code Online (Sandbox Code Playgroud)
这意味着已达到最大迭代次数.
这对数据意味着什么?是否可以在较早的时间(例如300次迭代)终止它?如果是这样,什么是合理的"上限"或最大迭代次数?
为了让您了解我正在训练的数据,我使用20,000 - 30,000次观察,每次观察14个特征.
谢谢,任何见解肯定会受到赞赏.
有没有办法直接在Jupyter中使用.Rmd文件?换句话说,有没有办法让 jupyter 渲染这样的文件: https: //github.com/yihui/knitr-examples/blob/master/023-engine-python.Rmd?
我喜欢 jupyter,也喜欢简单的语法.Rmd。
我正在尝试获取GBTClassifier的ROC曲线.
一种方法是重用BinaryClassificationMetrics,但文档中给出的路径(https://spark.apache.org/docs/latest/mllib-evaluation-metrics.html)仅为ROC曲线提供了4个值,如:
[0.0|0.0]
[0.0|0.9285714285714286]
[1.0|1.0]
[1.0|1.0]
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用"概率"列而不是"预测".但是,如果GBTClassifier我没有它,这个解决方案主要适用于RandomForestClassifier.
如何从BinaryClassificationMetrics绘制ROC曲线和精确回忆曲线
那么为任意分类器获得具有足够点的ROC曲线的一般/常用方法是什么?
我正在关注带有 Keras 教程的官方 TensorFlow,但我被困在这里:预测房价:回归 - 创建模型
为什么将激活函数用于预测连续值的任务?
代码是:
def build_model():
model = keras.Sequential([
keras.layers.Dense(64, activation=tf.nn.relu,
input_shape=(train_data.shape[1],)),
keras.layers.Dense(64, activation=tf.nn.relu),
keras.layers.Dense(1)
])
optimizer = tf.train.RMSPropOptimizer(0.001)
model.compile(loss='mse', optimizer=optimizer, metrics=['mae'])
return model
Run Code Online (Sandbox Code Playgroud) regression machine-learning neural-network keras activation-function
我想用与此类似的自定义颜色图绘制热图,尽管不完全相同。
我想要一个像这样的颜色图。在区间 [-0.6, 0.6] 中,颜色为浅灰色。高于 0.6,红色变深。低于 -0.6 的另一种颜色,比如蓝色,会增强。
如何使用 python 和 matplotlib 创建这样的颜色图?
到目前为止我所拥有的:在seaborn那里有一个命令seaborn.diverging_palette(220, 10, as_cmap=True),它可以产生一个从蓝-光-灰-红开始的颜色图。但是仍然与 [-0.6, 0.6] 没有差距。
python ×3
keras ×2
apache-spark ×1
colormap ×1
convergence ×1
jupyter ×1
knitr ×1
matplotlib ×1
pandas ×1
pybrain ×1
r ×1
r-markdown ×1
regression ×1
roc ×1
seaborn ×1