簡體   English   中英

在此數據集中查找相關性需要幫助

[英]Need help for finding a correlation in this dataset

我想在這個數據集中找到折扣金額和訂單頻率之間的相關性:

https://www.kaggle.com/datasets/zusmani/pakistans-largest-ecommerce-dataset

我只是在“折扣金額”和“訂購數量”變量之間嘗試它並且沒有相關性,所以我想嘗試將自變量更改為“訂購頻率”。 或者可能是“按月折扣金額”和“按月訂購頻率”,但我不知道該怎么做。

我相信折扣金額和訂單之間存在正相關關系,因為我只是在做 EDA 時檢查它,但是在做關於它的散點圖 plot 時我遇到了問題。

我在畫面中嘗試過,但如果您嘗試使用其他工具,如 phyton、excel 或其他任何工具,都可以。 謝謝。

不確定您的意思是什么“訂單頻率”。 我想那是(數量訂單/總計)。

library(tidyverse)

data01 <- rawdata |>                          # this is calculating the total correlation
    mutate(order_freq = qty_ordered / grand_total) |>    # calculate the order_freq
    select(discount_amount, order_freq) |>    # remove other column for simplicity (not neccesary)
    filter(is.finite(order_freq)) |>          # remove rows with infinite value
    cor()                                     # calculate the correlation

data02 <- rawdata |>    # this is calculating the correlation of each month
    mutate(order_freq = qty_ordered / grand_total) |> 
    select(Month, discount_amount, order_freq) |> 
    filter(!is.na(Month) & is.finite(order_freq)) |> 
    group_by(Month) |>                                   # calculate the correlation
    summarise(Corr = cor(discount_amount, order_freq))   #  of each month separately

> print(data01)
                discount_amount   order_freq
discount_amount     1.000000000 -0.001621597
order_freq         -0.001621597  1.000000000

> print(data02)
# A tibble: 12 x 2
   Month     Corr
   <int>    <dbl>
 1     1 -0.0113 
 2     2  0.0628 
 3     3 -0.0256 
 4     4  0.00990
 5     5 -0.00290
 6     6 -0.00881
 7     7 -0.00724
 8     8 -0.0294 
 9     9 -0.0254 
10    10 -0.0329 
11    11 -0.0313 
12    12 -0.00980

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM