我需要从较长的列表中随机取样而不进行替换(每个元素仅在样本中出现一次).我正在使用下面的代码,但现在我想知道:
抽样的目的是能够概括从样本分析到人群的结果.
import System.Random
-- | Take a random sample without replacement of size size from a list.
takeRandomSample :: Int -> Int -> [a] -> [a]
takeRandomSample seed size xs
| size < hi = subset xs rs
| otherwise = error "Sample size must be smaller than population."
where
rs = randomSample seed size lo hi
lo = 0
hi = length xs - 1
getOneRandomV g lo hi = randomR (lo, hi) g
rsHelper size …Run Code Online (Sandbox Code Playgroud) 将字符向量传递给 to 的dep.var.labels参数时stargazer,我希望因变量标签由该向量组成。但这似乎只有在模型是不同类型时才会发生。
data(mtcars)
m0 <- lm(mpg ~ hp, data=mtcars)
m1 <- lm(mpg ~ wt, data=mtcars)
m2 <- glm(cyl ~ disp, data=mtcars)
## Only shows the label 'foo' for both models.
stargazer(m0, m1, dep.var.labels=c('foo','bar'))
## shows 'foo' and 'bar' as labels.
stargazer(m0, m2, dep.var.labels=c('foo','bar'))
Run Code Online (Sandbox Code Playgroud)
即使模型类型相同,如何让观星者显示不同的因变量标签?
我正在构建一个依赖于机器学习算法输出的站点.站点的面向用户的部分所需要的只是算法的输出(一组项的类标签),可以从django模型中轻松存储和检索.该算法可以每天运行一次,并且不依赖于用户输入.
所以这部分网站只依赖于django相关的包.
但是,开发,调试和评估的算法使用许多其他Python包,例如scikit-learn,pandas,numpy,matplotlib,等,还需要挽救了许多套不同类的标签.
这些依赖项在部署时会导致一些问题heroku,因为numpy需要LAPACK/BLAS.在部署的应用程序中拥有尽可能少的依赖项似乎也是一种好习惯.
如何将机器学习部分与面向用户的部分分开,但是,是否仍然将它们集成到足以使算法的结果易于使用?
我想创建两个单独的项目,然后以某种方式写入面向用户的数据库,但这似乎会导致维护问题(管理依赖项,数据库模式的更改等).
据我所知,这个问题与使用不同的设置或数据库进行生产和开发有点不同,因为它更多的是关于管理不同的依赖集.
我正在从如下组织的文本文档中提取一些数据:
- "day 1"
- "Person 1"
- "Bill 1"
- "Person 2"
- "Bill 2"
Run Code Online (Sandbox Code Playgroud)
我可以将其读入一个看起来像这样的元组列表:
[(0,["day 1"]),(1,["Person 1"]),(2,["Bill 1"]),(1,["Person 2"]),(2,["Bill 2"])]
Run Code Online (Sandbox Code Playgroud)
每个元组的第一项表示标题级别,第二项表示与每个标题相关的信息.
我的问题是,如何获得如下所示的项目列表:
[["day 1","Person 1","Bill 1"],["day 1","Person 2","Bill 2"]]
Run Code Online (Sandbox Code Playgroud)
即每个最深嵌套项目的一个列表,包含来自其上方标题的所有信息.我得到的最接近的是:
f [] = []
f (x:xs) = row:f rest where
leaves = takeWhile (\i -> fst i > fst x) xs
rest = dropWhile (\i -> fst i > fst x) xs
row = concat $ map (\i -> (snd x):[snd i]) leaves
Run Code Online (Sandbox Code Playgroud)
这给了我这个:
[[["day 1"],["Intro 1"],["day …Run Code Online (Sandbox Code Playgroud) 我正在尝试str_extract_all从stringr包中使用R中的某些文本提取值,并且我想使用perl的regexp中的非匹配组(?:...)来提取和清除一行中的相关值.
运行此代码时:
library(stringr)
## Example string.
## Not the real string, but I get the same results with this one.
x <- 'WIDTH 4\nsome text that should not be matched.\n\nWIDTH 46 some text.'
## extract values
str_extract_all(x, perl('(?:WIDTH\\s+)[0-9]+'))
Run Code Online (Sandbox Code Playgroud)
我想得到这个结果:
[[1]]
[1] "4" "46"
Run Code Online (Sandbox Code Playgroud)
但我明白了:
[[1]]
[1] "WIDTH 4" "WIDTH 46"
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?