小编Fed*_*ina的帖子

从Python脚本获取当前目录的父级

我想从Python脚本中获取当前目录的父级.例如,我/home/kristina/desire-directory/scripts在这种情况下从欲望路径启动脚本/home/kristina/desire-directory

我知道sys.path[0]sys.但我不想解析sys.path[0]结果字符串.有没有其他方法可以在Python中获取当前目录的父级?

python sys sys.path

36
推荐指数
4
解决办法
7万
查看次数

如何根据条件删除pandas数据帧中的列?

我有一个pandas DataFrame,里面有很多NAN值.

我怎样才能删除这样的列number_of_na_values > 2000

我试着这样做:

toRemove = set()
naNumbersPerColumn = df.isnull().sum()
for i in naNumbersPerColumn.index:
    if(naNumbersPerColumn[i]>2000):
         toRemove.add(i)
for i in toRemove:
    df.drop(i, axis=1, inplace=True)
Run Code Online (Sandbox Code Playgroud)

有更优雅的方式吗?

python nan dataframe pandas

10
推荐指数
2
解决办法
2万
查看次数

cforest打印空树

我正在尝试使用cforest功能(R,派对包).

这就是我建造森林的方法:

library("party")
set.seed(42)
readingSkills.cf <- cforest(score ~ ., data = readingSkills, 
                         control = cforest_unbiased(mtry = 2, ntree = 50))
Run Code Online (Sandbox Code Playgroud)

然后我想打印第一棵树然后我做了

party:::prettytree(readingSkills.cf@ensemble[[1]],names(readingSkills.cf@data@get("input")))
Run Code Online (Sandbox Code Playgroud)

结果看起来像这样

     1) shoeSize <= 28.29018; criterion = 1, statistic = 89.711
       2) age <= 6; criterion = 1, statistic = 48.324
    3) age <= 5; criterion = 0.997, statistic = 8.917
      4)*  weights = 0 
    3) age > 5
      5)*  weights = 0 
  2) age > 6
    6) age <= 7; criterion = 1, statistic = 13.387
      7) …
Run Code Online (Sandbox Code Playgroud)

r party random-forest

5
推荐指数
2
解决办法
4181
查看次数

为什么输出h2o.kmeans函数中没有集群对象?

我想h2o.kmeansh2o包中使用函数.这是我的代码

clust <- h2o.kmeans(data = waterM, centers = 30,  key = "kmeansKey", iter.max = 1000, normalize = T, init = "none", dropNACols = F );
summary(clust@model);
Run Code Online (Sandbox Code Playgroud)

输出是

            Length Class  Mode   
params           6  -none- list   
centers      25560  -none- numeric
withinss        30  -none- numeric
tot.withinss     1  -none- numeric
size            30  -none- numeric
iter             1  -none- numeric
Run Code Online (Sandbox Code Playgroud)

为什么没有cluster包含整数向量的对象(从1:k),它表示每个点被分配到的簇?

r k-means h2o

3
推荐指数
1
解决办法
1683
查看次数

标签 统计

python ×2

r ×2

dataframe ×1

h2o ×1

k-means ×1

nan ×1

pandas ×1

party ×1

random-forest ×1

sys ×1

sys.path ×1