Rで何かをしたり、読書をするブログ

政府統計の総合窓口のデータや、OECDやUCIやのデータを使って、Rの練習をしています。ときどき、読書記録も載せています。

IEA Gender and Energy Employment Data Analysis 5 - splitting data by training data and testing data

UnsplashMohammad Ebeshが撮影した写真のMohammad Ebeshが撮影したイラスト素材

www.crosshyou.info

This post is contuniuation of above post.
Starting with this session, we'll be working on machine learning. First, we'll split the data into training data and test data.
First, let's load 'tidymodels' package.

I use initial_split(), training() and testing() to make training data set and test data set.

I will check whether there is a difference between the gap in the training data and the gap in the test data. I use t.test().

p-value is 0.7845. So, there is not statistically significant difference between test data's gap and training data's gap.

Also, let's make boxplot.

There is no difference between training(green) and testing(pink).

That's it. Thank you!

next post is

www.crosshyou.info

 

To read from the 1st post,

www.crosshyou.info

Today code is following below.

#
# load tidymodels package
library(tidymodels)
#
# data split
set.seed(253)
data_split <- initial_split(df, prop = 3/4)
train_data <- training(data_split)
test_data <- testing(data_split)
#
# check gap
t.test(train_data$gap, test_data$gap)
#
# Boxplot
bind_rows(
  tibble(
    data = "training",
    gap = train_data$gap
  ),
  tibble(
    data = "testing",
    gap = test_data$gap
  )
) |> 
  ggplot(aes(x = data, y = gap, group = data)) +
  geom_boxplot(aes(fill = data)) +
  theme_minimal()
#