-
Notifications
You must be signed in to change notification settings - Fork 1
/
Recommendation Engine.R
200 lines (152 loc) · 4.78 KB
/
Recommendation Engine.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
rm(list = ls())
load_lb <- function()
{
library(readxl)
library(tidyr)
library(dplyr)
library(caret)
library(rpart)
library(tree)
library(MASS)
require(xgboost)
require(data.table)
require(Matrix)
}
load_lb()
## Loading data
#challenge_data.csv: Contains attributes related to each challenge
challenge <- read.csv(file.choose())
head(challenge)
## Column checks
countMissing(challenge$challenge_ID)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 5606 (100.0%)
countDups(challenge$challenge_ID)
# Rows of Data: 5606
# Unique Values: 5606
# Duplicate Values: 0
# Missing Values: 0 (0.0%)
# Mode & Class: numeric, factor
countMissing(challenge$programming_language)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 5606 (100.0%)
countDups(challenge$programming_language)
# Rows of Data: 5606
# Unique Values: 3
# Duplicate Values: 5603
# Missing Values: 0 (0.0%)
# Mode & Class: numeric, integer
## changing programming language to factor
challenge$programming_language <- as.factor(challenge$programming_language)
mode(challenge$programming_language)
class(challenge$programming_language)
challenge$challenge_series_ID <- as.character(challenge$challenge_series_ID)
countMissing(challenge$challenge_series_ID)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 12 (0.2%)
# Non-missing Value: 5594 (99.8%)
countDups(challenge$challenge_series_ID)
# Rows of Data: 5606
# Unique Values: 436
# Duplicate Values: 5170
# Missing Values: 0 (0.0%)
# Mode & Class: numeric, factor
countMissing(challenge$total_submissions)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 352 (6.3%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 5254 (93.7%)
countDups(challenge$total_submissions)
# Rows of Data: 5606
# Unique Values: 1068
# Duplicate Values: 4538
# Missing Values: 352 (6.3%)
# Mode & Class: numeric, integer
countMissing(challenge$publish_date)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 5606 (100.0%)
challenge$author_ID <- as.character(challenge$author_ID)
countMissing(challenge$author_ID)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 39 (0.7%)
# Non-missing Value: 5567 (99.3%)
challenge$author_gender <- as.character(challenge$author_gender)
countMissing(challenge$author_gender)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 97 (1.7%)
# Non-missing Value: 5509 (98.3%)
challenge$author_org_ID <- as.character(challenge$author_org_ID)
countMissing(challenge$author_org_ID)
#TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 248 (4.4%)
# Non-missing Value: 5358 (95.6%)
countDups(challenge$author_org_ID)
# Rows of Data: 5606
# Unique Values: 1718
# Duplicate Values: 3888
# Missing Values: 0 (0.0%)
# Mode & Class: character, character
countMissing(challenge$category_id)
# TOTAL ROWS: 5606 (100.0%)
# Missing Values (NAs): 1841 (32.8%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 3765 (67.2%)
countDups(challenge$category_id)
# Rows of Data: 5606
# Unique Values: 195
# Duplicate Values: 5411
# Missing Values: 1841 (32.8%)
# Mode & Class: numeric, integer
##################################################################################
#train.csv: It contains the set of 13 challenges that were
#attempted by the same user in a sequence
train <- read.csv(file.choose())
head(train)
head(challenge)
## column checks
countMissing(train$challenge)
# TOTAL ROWS: 903916 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 903916 (100.0%)
countDups(train$challenge)
# Rows of Data: 903916
# Unique Values: 5348
# Duplicate Values: 898568
# Missing Values: 0 (0.0%)
# Mode & Class: numeric, factor
train$challenge_sequence <- as.factor(train$challenge_sequence)
countMissing(as.character(train$challenge_sequence))
# TOTAL ROWS: 903916 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 903916 (100.0%)
countMissing(train$user_id)
# TOTAL ROWS: 903916 (100.0%)
# Missing Values (NAs): 0 (0.0%)
# Empty Strings (""): 0 (0.0%)
# Non-missing Value: 903916 (100.0%)
countDups(train$user_id)
# Rows of Data: 903916
# Unique Values: 69532
# Duplicate Values: 834384
# Missing Values: 0 (0.0%)
# Mode & Class: numeric, integer
head(train)
head(challenge)
#Joining the tables
#Modifying the column name
New_names <- c("User_seq","User_id","chal_seq","challenge_ID")
colnames(train) <- New_names
combined <- left_join(train,challenge,by="challenge_ID")
head(combined)