<jupyter_start><jupyter_text>Store price prediction  1. Loading prerequisites 1.1. Libraries<jupyter_code>suppressWarnings({
    if(!require(dplyr)) install.packages("dplyr")
    if(!require(ggplot2)) install.packages("ggplot2")
    if(!require(caret)) install.packages("caret")
    if(!require(psych)) install.packages("psych")
    if(!require(mlbench)) install.packages("mlbench")
    if(!require(AppliedPredictiveModeling)) install.packages("AppliedPredictiveModeling")
    #if(!require(Hmisc)) install.packages("Hmisc",dependencies = TRUE)
    library(dplyr)
    library(ggplot2)
    library(caret)
    library(psych)
    library(mlbench)
    library(AppliedPredictiveModeling)
    #library(Hmisc)
})
options(repr.plot.width=6, repr.plot.height=4)
transparentTheme(trans = .4)<jupyter_output>Loading required package: dplyr

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

Loading required package: ggplot2
Loading required package: caret
Loading required package: lattice
Loading required package: psych

Attaching package: 'psych'

The following objects are masked from 'package:ggplot2':

    %+%, alpha

Loading required package: mlbench
Loading required package: AppliedPredictiveModeling<jupyter_text>1.2. Data<jupyter_code>DATA_PATH = "./data/"
train_raw = read.table(paste0(DATA_PATH,"Train.csv"), header = T, sep = ",")
test_raw = read.table(paste0(DATA_PATH,"Test.csv"), header = T, sep = ",")
pred_true = read.table(paste0(DATA_PATH,"Sample Submission.csv"), header = T, sep = ",")
dim(train_raw); dim(test_raw); dim(pred_true)<jupyter_output><empty_output><jupyter_text>2. Exploratory data analysis  2.1. Viewing the data<jupyter_code>head(train_raw, 10)<jupyter_output><empty_output><jupyter_text>2.2. Studying the original structure of the data<jupyter_code>sapply(train_raw, class)<jupyter_output><empty_output><jupyter_text>data = mutate(    train_raw,    InvoiceNo = factor(InvoiceNo),    StockCode = factor(StockCode),    Description = factor(Description),    Quantity = as.numeric(Quantity),    InvoiceDate = as.POSIXlt(InvoiceDate),    UnitPrice = as.numeric(UnitPrice),    CustomerID = factor(CustomerID),    Country = factor(Country))<jupyter_code>data = train_raw<jupyter_output><empty_output><jupyter_text>2.3 Summarizing the data in training set<jupyter_code>summary(data)<jupyter_output><empty_output><jupyter_text>2.5. Check for missing data<jupyter_code>sapply(data, function(x){sum(is.na(x))})<jupyter_output><empty_output><jupyter_text>2.6. Count of unique values in each fields<jupyter_code>sapply(data, function(x){length(unique(x))})
sapply(data[,-c(1,5)], function(x){round(cor(x,data[,1]),2)})<jupyter_output><empty_output><jupyter_text>This machine learning problem aims to predict the price of items in store, not forecast trend in prices overtime, therefore we may remove the InvoiceDate field.  Also the InvoiceNo is very little correlated to the other columns hence can't be used to fit the model<jupyter_code>data = select(data, select = -c(InvoiceNo,InvoiceDate))
features = names(data)[-4]
featurePlot(x = data[, features], 
            y = data$UnitPrice, 
            plot = "pairs")
#             type = c("p", "smooth")),
#             span = .5,
#             layout = c(3, 2))
preObj = preProcess(data, method=c("center","scale"))
data_scaled = predict(preObj,data)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12925364598227052, 'fraction_numerical': 0.010580497569345154, 'mean_word_length': 6.038229376257545, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '106328', 'license': 'MIT', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1136, 'n_words': 241, 'path': 'Case Studies/R/store_price_prediction/analysis.ipynb', 'repo_name': 'AnanduR32/Data_Science_R', 'size': '3497'}