为了澄清具有什么特征或属性,我可以说分析是推论性的或预测性的.
参加一个涉及推理和预测分析的数据科学课程.解释(我理解)是
推理
从群体中的小样本中引入假设,并且在较大/整个群体中看到它是正确的.
在我看来,这是概括.我认为诱导吸烟导致肺癌或二氧化碳导致全球变暖是推论分析.
预测
通过测量对象的变量来描述可能发生的事情.
我认为,确定哪些特征,行为,评论让人们反应良好,并使总统候选人足够受欢迎成为总统是一种预测分析(这也在课程中被触及).
我对这两个人有点困惑,因为它看起来有灰色区域或重叠.
贝叶斯推断是"推论",但我认为它用于预测,例如垃圾邮件过滤器或欺诈性金融交易识别.例如,银行可以使用先前对变量的观察(例如IP地址,发起人国家,受益人帐户类型等)并预测交易是否是欺诈性的.
我认为相对论是一种推论分析,它从观察和思想实验中引入了一个理论/假设,但它也预测了光的方向会被弯曲.
请帮助我理解什么是必须具有的属性,以将分析分类为推理或预测.
statistics inference machine-learning prediction data-science
题
在此数据文件中,使用"REGION"列将美国划分为四个区域.
创建一个查询,查找属于区域1或2的县,其名称以"Washington"开头,其POPESTIMATE2015大于其POPESTIMATE 2014.
此函数应返回带有columns = ['STNAME','CTYNAME']的5x2 DataFrame以及与census_df相同的索引ID(按索引递增排序).
码
def answer_eight():
counties=census_df[census_df['SUMLEV']==50]
regions = counties[(counties[counties['REGION']==1]) | (counties[counties['REGION']==2])]
washingtons = regions[regions[regions['COUNTY']].str.startswith("Washington")]
grew = washingtons[washingtons[washingtons['POPESTIMATE2015']]>washingtons[washingtons['POPESTIMATES2014']]]
return grew[grew['STNAME'],grew['COUNTY']]
outcome = answer_eight()
assert outcome.shape == (5,2)
assert list (outcome.columns)== ['STNAME','CTYNAME']
print(tabulate(outcome, headers=["index"]+list(outcome.columns),tablefmt="orgtbl"))
Run Code Online (Sandbox Code Playgroud)
错误
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-77-546e58ae1c85> in <module>()
6 return grew[grew['STNAME'],grew['COUNTY']]
7
----> 8 outcome = answer_eight()
9 assert outcome.shape == (5,2)
10 assert list (outcome.columns)== ['STNAME','CTYNAME']
<ipython-input-77-546e58ae1c85> in answer_eight()
1 def answer_eight():
2 counties=census_df[census_df['SUMLEV']==50]
----> 3 regions = …Run Code Online (Sandbox Code Playgroud) 我不确定这个错误意味着什么.我尝试计算时会发生此错误acc:
acc = accuracy.eval(feed_dict = {x: batch_images, y: batch_labels, keep_prob: 1.0})
Run Code Online (Sandbox Code Playgroud)
我试过查找解决方案,但我找不到任何在线.什么导致我的错误?
python machine-learning image-recognition data-science tensorflow
pandas 开发新手。如何使用先前看到的列中包含的值向前填充 DataFrame?
独立的示例:
import pandas as pd
import numpy as np
O = [1, np.nan, 5, np.nan]
H = [5, np.nan, 5, np.nan]
L = [1, np.nan, 2, np.nan]
C = [5, np.nan, 2, np.nan]
timestamps = ["2017-07-23 03:13:00", "2017-07-23 03:14:00", "2017-07-23 03:15:00", "2017-07-23 03:16:00"]
dict = {'Open': O, 'High': H, 'Low': L, 'Close': C}
df = pd.DataFrame(index=timestamps, data=dict)
ohlc = df[['Open', 'High', 'Low', 'Close']]
Run Code Online (Sandbox Code Playgroud)
这会产生以下数据帧:
print(ohlc)
Open High Low Close
2017-07-23 03:13:00 1.0 5.0 1.0 5.0
2017-07-23 03:14:00 …Run Code Online (Sandbox Code Playgroud) 我正在处理不平衡类的顺序标签问题,我想用它sample_weight来解决不平衡问题。基本上,如果我训练模型约10个时期,我会得到很好的结果。如果我训练更多的纪元,val_loss会不断下降,但结果会更糟。我猜测该模型只会检测到更多的主导类,从而损害较小的类。
该模型有两个输入,分别用于单词嵌入和字符嵌入,并且输入是从0到6的7种可能的类之一。
使用填充,我的词嵌入输入层的形状为,而词嵌入的输入层的形状(3000, 150)为(3000, 150, 15)。我将0.3拆分用于测试和训练数据,这意味着X_train用于单词嵌入(2000, 150)和(2000, 150, 15)用于char嵌入。y包含每个单词的正确类,并以7维的单热点向量编码,因此其形状为(3000, 150, 7)。y同样分为训练和测试集。然后将每个输入馈入双向LSTM。
输出是一个矩阵,为2000个训练样本的每个单词分配了7个类别之一,因此大小为(2000, 150, 7)。
首先,我只是尝试将长度定义sample_weight为np.array7,其中包含每个类的权重:
count = [list(array).index(1) for arrays in y for array in arrays]
count = dict(Counter(count))
count[0] = 0
total = sum([count[key] for key in count])
count = {k: count[key] / total for key in count}
category_weights = np.zeros(7)
for f …Run Code Online (Sandbox Code Playgroud) 嘿,我是Pandas的新手,我刚刚遇到过df.query().
df.query()当您可以使用括号表示法直接过滤Dataframe时,为什么人们会使用?官方的熊猫教程似乎也更喜欢后一种方法.
带括号表示法:
df[df['age'] <= 21]
Run Code Online (Sandbox Code Playgroud)
用pandas查询方法:
df.query('age <= 21')
Run Code Online (Sandbox Code Playgroud)
除了已经提到的一些风格或灵活性差异之外,还有一个规范首选 - 即在大型数据帧上执行操作?
我试图了解 Dask 在本地计算机上的使用模式。
具体来说,
Pandas 通过单个核心执行这些操作,这些操作对我来说需要几个小时。我的机器上有 8 个核心,因此,我想使用 Dask 尽可能地并行化这些操作。
我的问题如下: Dask 中执行此操作的两种方式有什么区别:
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()
Run Code Online (Sandbox Code Playgroud)
(1)
import dask.dataframe as dd
df = dd.from_pandas(
pd.DataFrame(iris.data, columns=iris.feature_names),
npartitions=2
)
df.mean().compute()
Run Code Online (Sandbox Code Playgroud)
(2)
import dask.dataframe as dd
from distributed import Client
client = Client()
df = client.persist(
dd.from_pandas(
pd.DataFrame(iris.data, columns=iris.feature_names),
npartitions=2
)
)
df.mean().compute()
Run Code Online (Sandbox Code Playgroud)
一种使用模式相对于另一种使用模式有什么好处?为什么我应该使用其中一种而不是另一种?
我尝试比较两者,一个是,pandas.unique()另一个是numpy.unique(),我发现后者实际上超越了第一个。
我不确定阁下是否是线性的。
谁能告诉我为什么在代码实现方面存在这样的差异?什么情况下我应该使用哪个?
我很喜欢 Altair 创建等值分布图!但是,我最大的问题是我无法弄清楚如何更改图例的大小。我已经通读了文档并尝试了几件事无济于事。
这是一个使用Altair 文档中按县划分的失业地图的示例。我添加了一个“配置”层来更改地图和图例上标题的字体大小。请注意“config”中代码的 .configure_legend() 部分。
counties = alt.topo_feature(data.us_10m.url, 'counties')
source = data.unemployment.url
foreground = alt.Chart(counties).mark_geoshape(
).encode(
color=alt.Color('rate:Q', sort="descending", scale=alt.Scale(scheme='plasma'), legend=alt.Legend(title="Unemp Rate", tickCount=6))
).transform_lookup(
lookup='id',
from_=alt.LookupData(source, 'id', ['rate'])
).project(
type='albersUsa'
).properties(
title="Unemployment Rate by County",
width=500,
height=300
)
config = alt.layer(foreground).configure_title(fontSize=20, anchor="middle").configure_legend(titleColor='black', titleFontSize=14)
config
Run Code Online (Sandbox Code Playgroud)
图像应该是这样的:
如果我像这样更改地图的大小:
counties = alt.topo_feature(data.us_10m.url, 'counties')
source = data.unemployment.url
foreground = alt.Chart(counties).mark_geoshape(
).encode(
color=alt.Color('rate:Q', sort="descending", scale=alt.Scale(scheme='plasma'), legend=alt.Legend(title="Unemp Rate", tickCount=6))
).transform_lookup(
lookup='id',
from_=alt.LookupData(source, 'id', ['rate'])
).project(
type='albersUsa'
).properties(
title="Unemployment Rate by County", …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现涉及几何级数(分割)的计算。有没有有效/高效的方法来做到这一点?该数据集有数百万行。我需要“Traded_quantity”列
| 标记 | 行动 | 交易数量 | ||
|---|---|---|---|---|
| 2019-11-05 | 09:25 | 0 | 0 | |
| 09:35 | 2 | 买 | 3 | |
| 09:45 | 0 | 0 | ||
| 09:55 | 1 | 买 | 4 | |
| 10:05 | 0 | 0 | ||
| 10:15 | 3 | 买 | 56 | |
| 10:24 | 6 | 买 | 8128 |
海龟 = 2(用户定义)
基本数量 = 1(用户定义)
def turtle_split(row):
if row['Action'] == 'BUY':
return base_quantity * (turtle ** row['Marker'] - 1) // (turtle - 1)
else:
return 0
df['Traded_quantity'] = df.apply(turtle_split, axis=1).round(0).astype(int)
Run Code Online (Sandbox Code Playgroud)
对于第 0 行,Traded_quantity 应为零(因为标记为零)
对于第一行,Traded_quantity 应为 (1x1) + (1x2) = 3(标记 2 将分为 1 和 1,第一个 1 将与 …
data-science ×10
python ×9
pandas ×4
dataframe ×2
altair ×1
dask ×1
database ×1
gis ×1
inference ×1
keras ×1
math ×1
numpy ×1
prediction ×1
statistics ×1
tensorflow ×1
vega-lite ×1