数仓可视化2--数仓分层

7 篇文章 0 订阅
4 篇文章 0 订阅

 1、dwd层--用户主题明细层

1.1、码表说明

action行为种类:
INSTALL("01", "install","安装"),
LAUNCH("02", "launch","启动"),
LOGIN("03", "login","登录"),
REGISTER("04", "register","注册"),
INTERACTIVE("05", "interactive","交互行为"),
EXIT("06", "exit","退出"),
PAGE_ENTER_H5("07", "page_enter_h5","网页页面进入"),
PAGE_ENTER_NATIVE("08", "page_enter_native","app页面进入")

eventtype事件类型:
VIEW("01", "view","浏览"),
CLICK("02", "click","点击"),
INPUT("03", "input","输入"),
SLIDE("04", "slide","滑动")
 

 1.2、用户启动日志表

ps:下面的数据导入是分区要对应上自己的分区, action='02'

create external table if not exists dwd_nshop.dwd_nshop_actlog_launch(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  launch_time_segment string comment '启动时间段',-- 启动时间段分为四个阶段(0-6、6-12、12-18、18-24)每个阶段用 1 2 3 4表示
  ct string comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dwd/user/dwd_nshop_actlog_launch/';
insert overwrite table dwd_nshop.dwd_nshop_actlog_launch partition(bdp_day='20231227')
  select
      customer_id ,
      device_num ,
      device_type ,
      os  ,
      os_version ,
      manufacturer,
      carrier,
      network_type,
      area_code,
          case when from_unixtime(cast(ct/1000+8*3600 as int),'HH') between 0 and 6 then 1
               when from_unixtime(cast(ct/1000+8*3600 as int),'HH') between 7 and 12 then 2
                when     from_unixtime(cast(ct/1000+8*3600 as int),'HH') between 13 and 18 then 3
                when      from_unixtime(cast(ct/1000+8*3600 as int),'HH') between 19 and 23 then 4 end launch_time_segment,
      ct
  from ods_nshop.ods_nshop_01_useractlog where action='02' and bdp_day='20231227';

1.3、用户产品浏览表 

action 是 ('07','08') 并且 event_type ='01';

create external table if not exists dwd_nshop.dwd_nshop_actlog_pdtview(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  target_id string comment '产品ID',
  duration int comment '停留时长',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dwd/user/dwd_nshop_actlog_pdtview/';
insert overwrite table dwd_nshop.dwd_nshop_actlog_pdtview partition (bdp_day='20231227')
select
    customer_id ,
  device_num ,
  device_type ,
  os ,
  os_version ,
  manufacturer ,
  carrier ,
  network_type,
  area_code ,
  get_json_object(extinfo,'$.target_id') target_id,
  duration,
  ct
from ods_nshop.ods_nshop_01_useractlog where action in ('07','08') and event_type='01' and bdp_day='20231227';

1.4、用户产品查询表

action ='05' 并且 event_type in ('01','04')

create external table if not exists dwd_nshop.dwd_nshop_actlog_pdtsearch(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  target_order string comment '查询排序方式',
  target_keys string comment '查询内容',
  target_id string comment '查询商品ID',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dwd/user/dwd_nshop_actlog_pdtsearch/';
insert overwrite table dwd_nshop.dwd_nshop_actlog_pdtsearch partition(bdp_day='20231227')
select
customer_id,
device_num,
device_type,
os,
os_version ,
manufacturer,
carrier,
network_type,
area_code,
get_json_object(extinfo,'$.target_order') as target_order,
get_json_object(extinfo,'$.target_keys') as target_keys,
target_id,
ct
from ods_nshop.ods_nshop_01_useractlog
lateral view explode(split(regexp_replace(get_json_object(extinfo,'$.target_ids'),'[\\[\\]\"]',''),',')) t as target_id
where bdp_day='20231227'
and action='05'
and event_type in('01','04');

1.5、用户关注店铺表

target_action='01' 并且 target_type = 3

create external table if not exists dwd_nshop.dwd_actlog_product_comment(
  user_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  carrier string comment '电信运营商',
  network_type string comment '网络类型',
  area_code string comment '地区编码',
  target_id string comment '产品ID',
  ct bigint comment '产生时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dwd/user/dwd_actlog_product_comment/';
with t as (
select 
    customer_id,
    device_num ,
  device_type ,
  os ,
  os_version ,
  manufacturer ,
  carrier ,
  network_type,
  area_code ,
  get_json_object(extinfo,'$.target_type') as target_type,
  get_json_object(extinfo,'$.target_action') as target_action,
  get_json_object(extinfo,'$.target_id') as target_id,
  ct
   from ods_nshop.ods_nshop_01_useractlog
   where bdp_day='20231227' and action='05' and event_type='02'
)
insert overwrite table dwd_nshop.dwd_actlog_product_comment partition(bdp_day='20231227')
select 
customer_id,
    device_num ,
  device_type ,
  os ,
  os_version ,
  manufacturer ,
  carrier ,
  network_type,
  area_code ,
  target_id,
  ct
from t where  target_type = '3'  and target_action='01';

2、交易主题 

ps:20191102有数据,所以添加了一个日期条件

create external table if not exists dwd_nshop.dwd_nshop_orders_details(
  order_id string comment '订单ID',
  order_status int comment '订单状态:5已收货(完成)|6投诉 7退货',
  supplier_code VARCHAR(20)  COMMENT '店铺ID',
  product_code VARCHAR(20)  COMMENT '商品ID',
  customer_id string comment '用户id',
  consignee_zipcode string comment '收货人地址',
  pay_type string comment '支付类型:线上支付 10 网上银行 11 微信 12 支付宝 | 线下支付(货到付款) 20 ',
  pay_nettype varchar(1)  COMMENT '支付网络方式:0 wifi | 1 4g | 2 3g |3 线下支付',
  pay_count int comment '支付次数',
  product_price DECIMAL(5,1)  COMMENT '购买商品单价',
  product_cnt INT  COMMENT '购买商品数量',
  weighing_cost DECIMAL(2,1) COMMENT '商品加权价格',
  district_money DECIMAL(4,1)  COMMENT '优惠金额',
  shipping_money DECIMAL(8,1)  COMMENT '运费金额',
  payment_money DECIMAL(10,1)  COMMENT '支付金额',
  is_activity  int COMMENT '1:参加活动|0:没有参加活动',
  order_ctime bigint comment '创建时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dwd/order/dwd_nshop_orders_details/';
with r as (
   select order_id,count(1) zfcs from ods_nshop.ods_02_orders_pay_records
   where from_unixtime(cast(pay_ctime/1000 as int),'yyyyMMdd') ='20191102'
   group by order_id
)
insert overwrite table dwd_nshop.dwd_nshop_orders_details partition(bdp_day='20231227')
select
   o.order_id,
   o.order_status,
   p.supplier_code,
   p.product_code,
   o.customer_id,
o.consignee_zipcode,
o.pay_type,
o.pay_nettype,
  r.zfcs,
  t.product_price,
t.product_cnt,
t.weighing_cost,
o.district_money,
o.shipping_money,
o.payment_money,
t.is_activity,
o.order_ctime

 from
 ods_nshop.ods_02_orders  o
  join
 ods_nshop.ods_02_order_detail  t
 on o.order_id = t.order_id  and   from_unixtime(cast(o.order_ctime/1000+3600*8 as int),'yyyyMMdd') ='20191102'
  join
 dim_nshop.dim_pub_product  p
 on  t.product_id = p.product_code
  join
 r  on r.order_id = o.order_id ;

 3、营销主题明细表

create external table if not exists dwd_nshop.dwd_nshop_releasedatas(
  customer_id string comment '用户id',
  device_num string comment '设备号',
  device_type string comment '设备类型',
  os string comment '手机系统',
  os_version string comment '手机系统版本',
  manufacturer string comment '手机制造商',
  area_code string comment '地区编码',
  release_sid string comment '投放请求id',
  release_ip string comment '投放方ip',
  release_session string comment '投放会话id',
  release_sources string comment '投放渠道',
  release_category string comment '投放浏览产品分类',
  release_product string comment '投放浏览产品',
  release_product_page string comment '投放浏览产品页',
  ct bigint comment '创建时间'
) partitioned by (bdp_day string)
stored as parquet
location '/data/nshop/dwd/release/dwd_nshop_releasedatas/'
with t1 as (
select 
b.customer_id,
a.device_num,
a.device_type ,
a.os ,
a.os_version ,
a.manufacturer ,
a.area_code ,
a.release_sid ,
parse_url(concat("http://127.0.0.1:8888/path?",a.release_params),'QUERY','ip') as release_ip,
a.release_session,
a.release_sources,
parse_url(concat("http://127.0.0.1:8888/path?",a.release_params),'QUERY','productPage') as release_product_page,
a.ct
from ods_nshop.ods_nshop_01_releasedatas a
join ods_nshop.ods_02_customer b
on a.device_num = b.customer_device_num
where a.bdp_day='20231227'
)
insert overwrite table dwd_nshop.dwd_nshop_releasedatas partition(bdp_day='20231227')
select 
t1.customer_id,
t1.device_num,
t1.device_type ,
t1.os ,
t1.os_version ,
t1.manufacturer ,
t1.area_code ,
t1.release_sid,
t1.release_ip,
t1.release_session,
t1.release_sources,
c.category_code,
b.page_target,
t1.release_product_page,
t1.ct
from t1 
join dim_nshop.dim_pub_page b
on t1.release_product_page = b.page_code and b.page_type = '4'
join  dim_nshop.dim_pub_product c
on b.page_target = c.product_code;

 

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: PyTorch 是一种广泛使用的深度学习框架,用于神经网络模型的构建和训练。而 t-SNE(t-distributed stochastic neighbor embedding)是一种常用的降维和数据可视化方法。在 PyTorch 中,可以使用 t-SNE 对模型的特征进行可视化。 t-SNE 可以将高维特征空间中的数据映射到二维或三维空间,使得数据在可视化上更容易理解。在 PyTorch 中,通过提取模型中的特定层的输出,我们可以获得特征向量。然后,使用 t-SNE 将这些特征向量映射到低维空间。 首先,从模型中选择一个合适的层作为特征提取器。一般来说,选择中间的某一层作为特征提取器,以便获取模型学到的抽象特征。然后,将待可视化的数据输入模型中进行前向传播,获取特定层的输出。 接下来,使用 t-SNE 算法对这些特征进行降维。t-SNE 在计算中考虑样本之间的相似度,将高维特征映射到低维空间,以保留样本间的相对距离。PyTorch 提供了一些实现 t-SNE 算法的库,比如 sklearn 中的 t-SNE。 最后,通过绘制降维后的特征向量,可以在二维或三维空间中可视化数据。可以使用散点图或其他合适的可视化方法展示数据。通过观察可视化结果,可以更好地理解数据的分布和特征之间的关系。 总结来说,使用 PyTorch 和 t-SNE,我们可以将模型的特征可视化,从而更好地理解数据的结构和模型的学习情况。这可以帮助我们分析模型的性能,优化特征选择,以及在数据挖掘和机器学习任务中做出更准确的决策。 ### 回答2: T-SNE是一种降维和可视化的算法,可用于将高维特征映射到二维或三维空间,以便更好地理解和分析数据。 在PyTorch中,我们可以使用T-SNE对特征进行可视化。首先,我们需要获取模型中的特征。通过提取中间层的输出,我们可以获得具有较低维度的特征向量。 接下来,我们使用T-SNE算法将这些特征向量映射到二维平面。PyTorch提供了许多实现T-SNE的库,如scikit-learn或TSNE库。 然后,我们可以使用matplotlib等库将特征可视化。可以使用不同的颜色或符号表示不同的类别或类别之间的差异。 特征可视化可以帮助我们理解数据之间的关系,发现数据中的模式或异常,并为进一步的分析提供指导。例如,我们可以根据特征可视化的结果进行聚类或分类任务。 需要注意的是,T-SNE是一种非确定性算法,因此对于不同的运行,可能会导致稍微不同的结果。因此,在进行分析和解释时,应该综合考虑多次运行的结果。 总之,通过PyTorch和T-SNE,我们可以将高维特征映射到二维空间,并使用可视化来更好地理解和分析数据,辅助我们在机器学习或数据分析中的工作。 ### 回答3: PyTorch是一个流行的开源深度学习框架,而t-SNE则是一种常用的降维和可视化算法。 特征可视化是指将高维数据的特征表示转化为低维空间,并通过可视化工具将其呈现出来,以便更好地理解数据。 在PyTorch中,我们可以使用t-SNE算法对提取的特征进行降维和可视化。首先,我们使用预训练的深度学习模型,如卷积神经网络(CNN),提取数据集中每个样本的特征表示。接下来,我们将这些特征输入到t-SNE算法中,通过迭代计算寻找合适的低维表示。 在PyTorch中实现t-SNE的方法有很多,可以使用sklearn库中的t-SNE算法,或者使用开源的tsne库。这些库都提供了简单易用的接口,可以方便地将特征数据作为输入,得到相应的低维投影结果。 一旦得到了特征的低维表示,我们可以使用各种可视化工具(如Matplotlib或Plotly)来展示这些特征点的分布。例如,我们可以使用散点图将不同类别的特征点呈现在二维平面上,或者使用颜色和形状来表示不同的类别信息。通过可视化,我们可以更好地理解数据的分布情况,发现不同类别之间的关系,甚至发现异常点或噪声。 总之,PyTorch提供了强大的深度学习框架,而t-SNE算法则是特征可视化的一种常用工具。通过将两者结合使用,我们可以更好地理解数据的特征表示,从而为模型训练和数据分析提供更多的洞察。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值