我正在尝试从深层嵌套的JSON字符串创建单个Pandas DataFrame对象.
JSON模式是:
{"intervals": [
{
pivots: "Jane Smith",
"series": [
{
"interval_id": 0,
"p_value": 1
},
{
"interval_id": 1,
"p_value": 1.1162791357932633e-8
},
{
"interval_id": 2,
"p_value": 0.0000028675012051504467
}
],
},
{
"pivots": "Bob Smith",
"series": [
{
"interval_id": 0,
"p_value": 1
},
{
"interval_id": 1,
"p_value": 1.1162791357932633e-8
},
{
"interval_id": 2,
"p_value": 0.0000028675012051504467
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
期望的结果我需要将其展平以制作表格:
Actor Interval_id Interval_id Interval_id ...
Jane Smith 1 1.1162 0.00000 ...
Bob Smith 1 1.1162 0.00000 ...
Run Code Online (Sandbox Code Playgroud)
第一列是Pivots …
我正在尝试使用Incanter数据分析库在Clojure中实现一个简单的逻辑回归示例.我已经成功编写了Sigmoid和Cost函数,但Incanter的BFGS最小化函数似乎给我带来了一些麻烦.
(ns ml-clj.logistic
(:require [incanter.core :refer :all]
[incanter.optimize :refer :all]))
(defn sigmoid
"compute the inverse logit function, large positive numbers should be
close to 1, large negative numbers near 0,
z can be a scalar, vector or matrix.
sanity check: (sigmoid 0) should always evaluate to 0.5"
[z]
(div 1 (plus 1 (exp (minus z)))))
(defn cost-func
"computes the cost function (J) that will be minimized
inputs:params theta X matrix and Y vector"
[X y]
(let
[m (nrow …Run Code Online (Sandbox Code Playgroud) statistics machine-learning clojure incanter logistic-regression
我想创建一个函数来保存我认为是垃圾邮件的字符串的频率.我正在尝试使用可以更新的原子地图,因为我给地图一个新的字符串.
期望的行为
user> (train-word spam "FREE")
{"FREE": 1}
user> (train-word spam "FREE")
{"FREE" : 2}
user> (train-word spam "MONEY")
{"FREE" : 2 "MONEY" : 1}
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经尝试过
(def spam (atom {}))
(defn train-word [m word]
(swap! update-in m [word]
(fn [old] (inc (or old 0)))))
Run Code Online (Sandbox Code Playgroud)
但是会产生错误:
clojure.lang.Atom cannot be cast to clojure.lang.Associative clojure.lang.RT.assoc (RT.java:702)
Run Code Online (Sandbox Code Playgroud)
我是Clojure的新手,所以我在Python中做了一个快速原型
from collections import defaultdict
spam = defaultdict(int)
def train_word(word, spam):
spam[word] += 1
Run Code Online (Sandbox Code Playgroud)
使用atom来管理状态以更新当前值以及添加新值的惯用方法是什么?谢谢!
我有一个弹性搜索查询,它查询索引,然后根据特定字段进行聚合sender_not_analyzed.然后,我在同一个字段上使用术语聚合sender_not_analyzed,返回顶部"发件人"的存储桶.我的查询目前是:
{
"size": 0,
"query": {
"regexp": {
"sender_not_analyzed": ".*[@].*"
}
},
"aggs": {
"sender-stats": {
"terms": {
"field": "sender_not_analyzed"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
返回看起来像这样的桶:
"aggregations": {
"sender-stats": {
"buckets": [
{
"key": "<Mike <mike@fizzbuzz.com>@MISSING_DOMAIN>",
"doc_count": 5017
},
{
"key": "jon.doe@foo.com",
"doc_count": 3963
},
{
"key": "jane.doe@foo.com",
"doc_count": 2857
},
{
"key": "jon.doe@bar.com",
"doc_count":1544
}
Run Code Online (Sandbox Code Playgroud)
我如何编写聚合,以便为每个唯一的电子邮件域获取单个存储桶,例如,foo.com将具有doc_count(3963 + 2857)6820?我可以使用正则表达式聚合来完成此操作,还是需要编写某种自定义分析器来将@中的字符串拆分为字符串的末尾?
我已经阅读了这两个问题,这些 问题似乎与我正在努力解决的问题相同,即我的按钮文本我想显示为上标.在我onCreateView添加的方法的片段类中
if (rootView.findViewById(R.id.squared) != null) {
((TextView) rootView.findViewById(R.id.squared)).setText(Html.fromHtml("X <sup><small> 2 </small></sup>"));
rootView.findViewById(R.id.squared).setOnClickListener(this);
}
if (rootView.findViewById(R.id.cubed) != null) {
((TextView) rootView.findViewById(R.id.cubed)).setText(Html.fromHtml("X <sup><small> 3 </small></sup>"));
rootView.findViewById(R.id.cubed).setOnClickListener(this);
Run Code Online (Sandbox Code Playgroud)
在我fragment_main的按钮被编码为
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:fontFamily="helvetica"
android:id="@+id/squared"
android:layout_weight="0.25"
style="?android:attr/borderlessButtonStyle"
android:textSize="15sp" />
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:fontFamily="helvetica"
android:id="@+id/cubed"
android:layout_weight="0.25"
style="?android:attr/borderlessButtonStyle"
android:textSize="15sp" />
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的应用程序时,布局不会有任何上标文本.

即使我将文本大小更改15sp为10sp,文本也只会变小,但不会上标.我做得不好?
clojure ×2
aggregation ×1
android ×1
formatting ×1
incanter ×1
json ×1
pandas ×1
python ×1
statistics ×1