小编Clo*_*ave的帖子

读取制表符分隔的文本文件

我试图使用以下代码从R中的链接读取数据,但我不断收到警告消息,并且数据帧不能正确读取数据.

url <- 'https://onlinecourses.science.psu.edu/stat501/sites/onlinecourses.science.psu.edu.stat501/files/data/leukemia_remission.txt'
df <- read.table(url, sep = '\t',header = F, skip = 2,quote='', comment='')
Run Code Online (Sandbox Code Playgroud)

你能告诉我需要改变什么才能读取数据

编辑

添加数据片段

REMISS  CELL    SMEAR   INFIL   LI  BLAST   TEMP
1   0.8 0.83    0.66    1.9 1.1 1
1   0.9 0.36    0.32    1.4 0.74    0.99
0   0.8 0.88    0.7 0.8 0.18    0.98
0   1   0.87    0.87    0.7 1.05    0.99
1   0.9 0.75    0.68    1.3 0.52    0.98
0   1   0.65    0.65    0.6 0.52    0.98
1   0.95    0.97    0.92    1   1.23    0.99
0   0.95    0.87 …
Run Code Online (Sandbox Code Playgroud)

r

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

查找值的百分位数

我有一个类似的值数组,[1,2,3,4,5]我需要找到每个值的百分位数。我期望的输出类似于[0,25,50,75,100].

我在 numpy 中搜索了一个可以得到想要的结果的 API 并找到了,np.percentile但结果恰恰相反。给定一个百分位值,它将使用输入列表作为分布找到一个值。

有没有api或方法来获得这个?谢谢

python

6
推荐指数
2
解决办法
3580
查看次数

参数(n_estimators)的参数值必须是序列

我收到错误,不知道如何解决它.你能帮忙吗?整个代码可以在https://github.com/kthouz/NYC_Green_Taxi/blob/master/NYC%20Green%20Taxi.ipynb找到

通过网格搜索优化n_estimator

def optimize_num_trees(alg,param_test,scoring_method,train,predictors,target):
    """
    This functions is used to tune paremeters of a predictive algorithm
    alg: sklearn model,
    param_test: dict, parameters to be tuned
    scoring_method: str, method to be used by the cross-validation to valuate the model
    train: pandas.DataFrame, training data
    predictors: list, labels to be used in the model training process. They should be in the column names of dtrain
    target: str, target variable
    """
    gsearch = GridSearchCV(estimator=alg, param_grid = param_test, scoring=scoring_method,n_jobs=2,iid=False,cv=5)
    gsearch.fit(train[predictors],train[target])
    return gsearch

# …
Run Code Online (Sandbox Code Playgroud)

python

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

熊猫计算具有列表而不是单个值的列的平均值

我有一个 Pandas 数据框,它有一列,每一行都有一个值列表。我需要使用每一行的相应值来计算平均值。那就是我需要列表中八个值的平均值。列表中的每个元素都是一个变量的值

>>> df_ex
0    [1, 2, 3, 4, 5, 6, 7, 8]
1    [2, 3, 4, 5, 6, 7, 8, 1]
Run Code Online (Sandbox Code Playgroud)

我尝试将其转换为 numpy 数组,然后采取措施,但我不断收到错误消息TypeError: unsupported operand type(s) for /: 'list' and 'int'。我知道我应该将其转换为列而不是使用列表,但在我的上下文中这是不可能的。关于我如何做到这一点的任何想法?

python numpy dataframe pandas

5
推荐指数
1
解决办法
5191
查看次数

设置火花配置

我正在尝试在 pyspark shell 中设置一些 spark 参数的配置。

我尝试了以下

spark.conf.set("spark.executor.memory", "16g")

要检查是否已设置执行程序内存,我做了以下 spark.conf.get("spark.executor.memory")

返回"16g".

我试图通过sc使用 来检查它sc._conf.get("spark.executor.memory")

然后返回"4g"

为什么这两个返回不同的值以及设置这些配置的正确方法是什么。

另外,我正在摆弄一堆参数,例如 "spark.executor.instances" "spark.executor.cores" "spark.executor.memory" "spark.executor.memoryOverhead" "spark.driver.memory" "spark.driver.cores" "spark.driver.memoryOverhead" "spark.memory.offHeap.size" "spark.memory.fraction" "spark.task.cpus" "spark.memory.offHeap.enabled " "spark.rpc.io.serverThreads" "spark.shuffle.file.buffer"

有没有办法为所有变量设置配置。

编辑

我需要以编程方式设置配置。完成spark-submit或启动 pyspark shell后如何更改它?我正在尝试减少我的工作的运行时间,我正在通过多次迭代更改火花配置并记录运行时间。

python-3.x apache-spark apache-spark-sql pyspark

5
推荐指数
1
解决办法
1万
查看次数

有效的方法来替换pandas数据帧中每个单元格的值

我有两个数据帧,一个是topic_目标数据帧,tw哪个是源数据帧.这topic_是一个按字矩阵的主题,其中每个单元格存储在特定主题中出现的单词的概率.我topic_使用numpy.zeros 将数据帧初始化为零.tw数据框的样本 -

print(tw)
    topic_id                                     word_prob_pair
0          0  [(customer, 0.061703717964), (team, 0.01724444...
1          1  [(team, 0.0260560163563), (customer, 0.0247838...
2          2  [(customer, 0.0171786268847), (footfall, 0.012...
3          3  [(team, 0.0290787264225), (product, 0.01570401...
4          4  [(team, 0.0197917953222), (data, 0.01343226630...
5          5  [(customer, 0.0263740639141), (team, 0.0251677...
6          6  [(customer, 0.0289764173735), (team, 0.0249938...
7          7  [(client, 0.0265082412402), (want, 0.016477447...
8          8  [(customer, 0.0524006965405), (team, 0.0322975...
9          9  [(generic, 0.0373422774996), (product, 0.01834...
10        10  [(customer, 0.0305256248248), …
Run Code Online (Sandbox Code Playgroud)

python numpy pandas

4
推荐指数
1
解决办法
406
查看次数

Pandas - 将分类列转换为二进制编码形式

我有一个看起来像这样的数据集 -

     yyyy      month        tmax         tmin
0    1908    January         5.0         -1.4
1    1908   February         7.3          1.9
2    1908      March         6.2          0.3
3    1908      April         7.4          2.1
4    1908        May        16.5          7.7
5    1908       June        17.7          8.7
6    1908       July        20.1         11.0
7    1908     August        17.5          9.7
8    1908  September        16.3          8.4
9    1908    October        14.6          8.0
10   1908   November         9.6          3.4
11   1908   December         5.8         -0.3
12   1909    January         5.0          0.1
13   1909   February         5.5         -0.3
14   1909      March         5.6 …
Run Code Online (Sandbox Code Playgroud)

python pandas

4
推荐指数
1
解决办法
2410
查看次数

将Pandas MultiIndex DataFrame转换为嵌套字典

我有一个熊猫多索引数据框,我想将其输出为嵌套字典。

# create the dataset
data = {'clump_thickness': {(0, 0): 274.0, (0, 1): 19.0, (1, 0): 67.0, (1, 1): 12.0, (2, 0): 83.0, (2, 1): 45.0, (3, 0): 16.0, (3, 1): 40.0, (4, 0): 4.0, (4, 1): 54.0, (5, 0): 0.0, (5, 1): 69.0, (6, 0): 0.0, (6, 1): 0.0, (7, 0): 0.0, (7, 1): 0.0, (8, 0): 0.0, (8, 1): 0.0, (9, 0): 0.0, (9, 1): 0.0}}
df = pd.DataFrame(data)
df.head()
#      clump_thickness
# 0 0            274.0
#   1 …
Run Code Online (Sandbox Code Playgroud)

python pandas

4
推荐指数
1
解决办法
2240
查看次数

与Apache Spark和scikit_learn之间的KMeans结果不一致

我正在使用PySpark对数据集进行聚类.为了找到我在一系列值(2,20)上进行聚类的聚类数,并找到wsse每个值的(聚类内的平方和)值k.这是我发现一些不寻常的东西.根据我的理解,当你增加簇的数量时,wsse单调减少.但结果我说不然.我wsse只显示前几个群集

Results from spark

For k = 002 WSSE is 255318.793358
For k = 003 WSSE is 209788.479560
For k = 004 WSSE is 208498.351074
For k = 005 WSSE is 142573.272672
For k = 006 WSSE is 154419.027612
For k = 007 WSSE is 115092.404604
For k = 008 WSSE is 104753.205635
For k = 009 WSSE is 98000.985547
For k = 010 WSSE is 95134.137071
Run Code Online (Sandbox Code Playgroud)

如果你看一下wsse对价值k=5和 …

python k-means scikit-learn apache-spark pyspark

4
推荐指数
1
解决办法
658
查看次数

如何归一化非正态分布?

呐

我有上述分布,均值为-0.02,标准差为0.09,样本量为13905

我只是不确定为什么鉴于样本量大,分布是左偏的。从 bin [-2.0 到 -0.5],该 bin 中只有 10 个样本计数/异常值,这解释了形状。

我只是想知道是否可以标准化以使其更平滑和“正态”分布。目的是将其输入模型,同时降低预测器的标准误差。

python graph normal-distribution normalization

4
推荐指数
1
解决办法
2788
查看次数