library(e1071)
library(caret)
## Warning: package 'caret' was built under R version 4.3.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.2
## Loading required package: lattice
library(RWeka)
## Warning: package 'RWeka' was built under R version 4.3.2
library(kernlab)
##
## Attaching package: 'kernlab'
## The following object is masked from 'package:ggplot2':
##
## alpha
library(rminer)
## Warning: package 'rminer' was built under R version 4.3.3
library(matrixStats)
## Warning: package 'matrixStats' was built under R version 4.3.3
library(knitr)
## Warning: package 'knitr' was built under R version 4.3.2
Import NA_sales_filtered.csv and set stringsAsFactors = False.
Create a data frame with all of the variables except for Name.
Transform character variables except for Name to factors.
Create the training and testing sets based on percentage split – 70% for training and 30% for testing.
# Step 1: Import the CSV file
data <- read.csv('NA_sales_filtered.csv', stringsAsFactors = FALSE)
# Step 2: Create a data frame without the 'Name' column
data_without_name <- data[, !(names(data) %in% c('Name'))]
# Step 3: Convert character variables to factors, except for 'Name'
data_factors <- data_without_name
for (col in names(data_factors)) {
if (is.character(data_factors[[col]])) {
data_factors[[col]] <- as.factor(data_factors[[col]])
}
}
# Step 4: Create training and testing sets (70%-30% split)
set.seed(500)
inTrain <- createDataPartition(y = data_factors$NA_Sales, p = 0.70, list = FALSE)
# Split the data into training and test sets
train_set <- data_factors[inTrain, ]
test_set <- data_factors[-inTrain, ]
MLP <- make_Weka_classifier("weka/classifiers/functions/MultilayerPerceptron")
model_default <- MLP( NA_Sales ~ .,data = train_set)
model_default
## Linear Node 0
## Inputs Weights
## Threshold -0.28914060925810553
## Node 1 -0.5409345186730656
## Node 2 -0.4487480821342062
## Node 3 -0.5733786758332217
## Node 4 -0.17887903610375597
## Node 5 -0.23454086764371498
## Node 6 -0.8187507822184964
## Node 7 -0.29517016741293534
## Node 8 -0.35482927656595586
## Node 9 -0.3089077109566553
## Node 10 -0.28205375402802174
## Node 11 -0.34664694773048643
## Node 12 -0.4349540416151832
## Node 13 -0.49182458384660677
## Node 14 -0.4979055784057645
## Node 15 -0.45656754161755003
## Node 16 -0.30268094146074237
## Node 17 -0.3498638102140591
## Node 18 -0.2713309500695388
## Node 19 -0.2931335698640358
## Sigmoid Node 1
## Inputs Weights
## Threshold -0.9264420289688788
## Attrib Platform=3DS -0.07117757710735799
## Attrib Platform=DS 2.790570722915713
## Attrib Platform=GBA 1.244947419831184
## Attrib Platform=GC 1.6861507253621533
## Attrib Platform=PC 1.200786292863451
## Attrib Platform=PS -2.0246616148018948
## Attrib Platform=PS2 0.3687208235187921
## Attrib Platform=PS3 1.0353332171162082
## Attrib Platform=PS4 -2.6993862090431047
## Attrib Platform=PSP 0.906553335220546
## Attrib Platform=PSV 1.4508964117394003
## Attrib Platform=Wii 2.4030026659604795
## Attrib Platform=WiiU 2.9956880817528515
## Attrib Platform=X360 0.4954974492423241
## Attrib Platform=XB -1.4813162164941316
## Attrib Platform=XOne 1.9256718786620215
## Attrib Genre=Action -0.48297880705955254
## Attrib Genre=Adventure -1.2312278314266043
## Attrib Genre=Fighting 2.2381460503283055
## Attrib Genre=Misc -0.26152229587567977
## Attrib Genre=Platform 0.38240752719619736
## Attrib Genre=Puzzle -0.19553188436132388
## Attrib Genre=Racing 2.468427977217465
## Attrib Genre=Role-Playing 4.1738633805923495
## Attrib Genre=Shooter -1.0715914760004086
## Attrib Genre=Simulation -0.5495347646660181
## Attrib Genre=Sports 2.495711740000567
## Attrib Genre=Strategy 0.8358528305073549
## Attrib Rating=E -0.6649213936269381
## Attrib Rating=E10+ 1.3724211481487743
## Attrib Rating=M -2.133960288706931
## Attrib Rating=missing 1.3050034588017358
## Attrib Rating=T 2.7459409880435097
## Attrib Critic_Score -3.335597075910612
## Attrib Critic_Count -1.3704314472599601
## Attrib User_Score 4.107036102395181
## Attrib User_Count -10.98971400263024
## Sigmoid Node 2
## Inputs Weights
## Threshold -0.7142074480830007
## Attrib Platform=3DS -0.6559274486074085
## Attrib Platform=DS 2.267782862773478
## Attrib Platform=GBA 2.2057343615052982
## Attrib Platform=GC 2.8881958400307
## Attrib Platform=PC -2.623481619322979
## Attrib Platform=PS -1.7954112713965884
## Attrib Platform=PS2 0.6030206738997165
## Attrib Platform=PS3 0.3202995679022712
## Attrib Platform=PS4 -0.20432164398576488
## Attrib Platform=PSP 2.8722885612225104
## Attrib Platform=PSV 1.0345696272937313
## Attrib Platform=Wii 1.6169299593018076
## Attrib Platform=WiiU 2.634653161719834
## Attrib Platform=X360 0.9621259235800841
## Attrib Platform=XB -0.5700042801331316
## Attrib Platform=XOne -0.7888371451735426
## Attrib Genre=Action -1.1642464464953994
## Attrib Genre=Adventure -2.1224895641277057
## Attrib Genre=Fighting 2.380978018043433
## Attrib Genre=Misc -0.47238745983034314
## Attrib Genre=Platform 0.4193985968488338
## Attrib Genre=Puzzle 0.5104848064677195
## Attrib Genre=Racing 1.2708768396728285
## Attrib Genre=Role-Playing 2.4989717305550023
## Attrib Genre=Shooter -1.6399679631824131
## Attrib Genre=Simulation 2.0052044842324634
## Attrib Genre=Sports 2.0490372411658666
## Attrib Genre=Strategy 1.923341360259727
## Attrib Rating=E 0.8967229513366292
## Attrib Rating=E10+ -0.05346886862440188
## Attrib Rating=M 3.3380632432827335
## Attrib Rating=missing 0.4514907321963767
## Attrib Rating=T -2.3007874480361985
## Attrib Critic_Score 4.87435447774432
## Attrib Critic_Count -6.147818445081773
## Attrib User_Score -0.9091208798902358
## Attrib User_Count -4.590135672430675
## Sigmoid Node 3
## Inputs Weights
## Threshold -0.6483505715544842
## Attrib Platform=3DS 0.11328663429449286
## Attrib Platform=DS 0.018932442403594266
## Attrib Platform=GBA 0.2989824793974258
## Attrib Platform=GC 0.23286938390574974
## Attrib Platform=PC -1.6460130836262215
## Attrib Platform=PS 0.9971621784757864
## Attrib Platform=PS2 -0.18262452062374304
## Attrib Platform=PS3 0.5223647917939301
## Attrib Platform=PS4 6.422587707050444
## Attrib Platform=PSP -0.7755581016265762
## Attrib Platform=PSV 0.008500131395142909
## Attrib Platform=Wii 1.1402481520696075
## Attrib Platform=WiiU 0.6275737413767646
## Attrib Platform=X360 0.3465271648655783
## Attrib Platform=XB 1.2495074887236504
## Attrib Platform=XOne -0.5266663400071295
## Attrib Genre=Action 0.3772102599425006
## Attrib Genre=Adventure 1.0959966921859006
## Attrib Genre=Fighting -0.12750597274031342
## Attrib Genre=Misc -0.6234218953422802
## Attrib Genre=Platform 0.15122282147666255
## Attrib Genre=Puzzle 0.5860948354987245
## Attrib Genre=Racing 0.752496284752029
## Attrib Genre=Role-Playing 0.507298871197925
## Attrib Genre=Shooter -1.1865160644696175
## Attrib Genre=Simulation 2.986073908725433
## Attrib Genre=Sports -2.393546752960555
## Attrib Genre=Strategy 4.158774517362847
## Attrib Rating=E -1.0004303957910816
## Attrib Rating=E10+ 0.42448051655163316
## Attrib Rating=M -1.3004831641822419
## Attrib Rating=missing 2.646971333101356
## Attrib Rating=T 1.2497833558487108
## Attrib Critic_Score -0.934676842779186
## Attrib Critic_Count 0.2064077823465255
## Attrib User_Score -0.48697979785425244
## Attrib User_Count -11.46104620029738
## Sigmoid Node 4
## Inputs Weights
## Threshold -0.7055634561130338
## Attrib Platform=3DS 3.4930153837054427
## Attrib Platform=DS -0.923330754147978
## Attrib Platform=GBA 0.0134893398639218
## Attrib Platform=GC 0.07411159290315128
## Attrib Platform=PC 1.9846659200216947
## Attrib Platform=PS 0.23237072738918016
## Attrib Platform=PS2 0.9503609557252326
## Attrib Platform=PS3 -1.7601863682458379
## Attrib Platform=PS4 -0.12488495858530864
## Attrib Platform=PSP 1.1025354750138374
## Attrib Platform=PSV 1.2414798319016225
## Attrib Platform=Wii 2.3314814316086534
## Attrib Platform=WiiU 2.2603485418052216
## Attrib Platform=X360 -1.459950181286497
## Attrib Platform=XB 0.3946141811580204
## Attrib Platform=XOne -0.48794100379243527
## Attrib Genre=Action 1.2173659299332977
## Attrib Genre=Adventure 0.10802821320703047
## Attrib Genre=Fighting -0.2718150619752991
## Attrib Genre=Misc 0.1068680149197313
## Attrib Genre=Platform -0.12020716434359852
## Attrib Genre=Puzzle 0.8101384111495965
## Attrib Genre=Racing 1.3550892531871883
## Attrib Genre=Role-Playing 3.4889415669945354
## Attrib Genre=Shooter 0.44536268304036275
## Attrib Genre=Simulation -0.32240249463094284
## Attrib Genre=Sports -1.6680818576869387
## Attrib Genre=Strategy 1.3121414457842528
## Attrib Rating=E 1.7431570857333263
## Attrib Rating=E10+ -1.6985342642247043
## Attrib Rating=M 2.707809718343044
## Attrib Rating=missing 0.5397125425226815
## Attrib Rating=T -1.2350701534355384
## Attrib Critic_Score 2.8815429089619133
## Attrib Critic_Count -2.1191909057305365
## Attrib User_Score -2.802689258097924
## Attrib User_Count -6.533588125124944
## Sigmoid Node 5
## Inputs Weights
## Threshold -0.7744441155321008
## Attrib Platform=3DS 2.261905308530287
## Attrib Platform=DS 0.6341165260603663
## Attrib Platform=GBA 1.3191704569746088
## Attrib Platform=GC 1.3278007515333443
## Attrib Platform=PC -0.6711827309200307
## Attrib Platform=PS 1.1029414742225092
## Attrib Platform=PS2 1.0653364685185136
## Attrib Platform=PS3 0.1966373465308934
## Attrib Platform=PS4 0.454676439712122
## Attrib Platform=PSP 1.662305101524576
## Attrib Platform=PSV 0.9808855404895782
## Attrib Platform=Wii -0.3164330452431893
## Attrib Platform=WiiU 0.38094980642523535
## Attrib Platform=X360 0.7739807990840952
## Attrib Platform=XB -0.5221740192536345
## Attrib Platform=XOne 0.0915923946619911
## Attrib Genre=Action 0.9876819251815798
## Attrib Genre=Adventure 0.7786859249469068
## Attrib Genre=Fighting 0.49640877632940916
## Attrib Genre=Misc 0.7951890250996914
## Attrib Genre=Platform 0.5533316988970572
## Attrib Genre=Puzzle 1.1008575029265262
## Attrib Genre=Racing 0.04996950699428476
## Attrib Genre=Role-Playing 0.6416979109032179
## Attrib Genre=Shooter 1.8611818226174222
## Attrib Genre=Simulation 0.48849207332354655
## Attrib Genre=Sports 0.8514142370719379
## Attrib Genre=Strategy -0.8854591471985506
## Attrib Rating=E 0.6333249881869851
## Attrib Rating=E10+ 0.99642470611493
## Attrib Rating=M -0.05564641590167821
## Attrib Rating=missing 0.8135163053866291
## Attrib Rating=T -0.018606684294335603
## Attrib Critic_Score 0.6698151551341079
## Attrib Critic_Count 1.418991427090904
## Attrib User_Score -2.2975402537104386
## Attrib User_Count -15.558324684508564
## Sigmoid Node 6
## Inputs Weights
## Threshold -0.7861055367411008
## Attrib Platform=3DS -0.9385462759361476
## Attrib Platform=DS 0.02423991498128472
## Attrib Platform=GBA 2.0532869163589247
## Attrib Platform=GC 0.9923655053732848
## Attrib Platform=PC -0.34438029666198566
## Attrib Platform=PS -0.6627333857923958
## Attrib Platform=PS2 1.5315431885679684
## Attrib Platform=PS3 1.3794042960624229
## Attrib Platform=PS4 -0.20492877320468475
## Attrib Platform=PSP 1.4123274080107717
## Attrib Platform=PSV -0.320711027817721
## Attrib Platform=Wii 0.8606763456590779
## Attrib Platform=WiiU -0.6943661552280961
## Attrib Platform=X360 1.0023082434268542
## Attrib Platform=XB 1.7631318674282674
## Attrib Platform=XOne 2.253831009827932
## Attrib Genre=Action 1.8636431312808834
## Attrib Genre=Adventure 0.6908566665249244
## Attrib Genre=Fighting 1.20093667590013
## Attrib Genre=Misc -0.29287949348778597
## Attrib Genre=Platform 0.7895668280664875
## Attrib Genre=Puzzle 0.7534937476908383
## Attrib Genre=Racing 2.183774582975432
## Attrib Genre=Role-Playing -0.3088566342118225
## Attrib Genre=Shooter 1.5669950259719372
## Attrib Genre=Simulation -0.646266556246836
## Attrib Genre=Sports 0.644979188663811
## Attrib Genre=Strategy -0.93287996338209
## Attrib Rating=E 0.8148820153993995
## Attrib Rating=E10+ 0.6158937299970263
## Attrib Rating=M -1.6116409927129127
## Attrib Rating=missing 1.051043028285426
## Attrib Rating=T 1.365907968139207
## Attrib Critic_Score 1.622675411135854
## Attrib Critic_Count -0.07524577736976804
## Attrib User_Score -2.3568536695183147
## Attrib User_Count -8.096443409324863
## Sigmoid Node 7
## Inputs Weights
## Threshold -0.5885143371909587
## Attrib Platform=3DS 1.254790801430788
## Attrib Platform=DS 1.1002682106704604
## Attrib Platform=GBA -0.8445578809361555
## Attrib Platform=GC 1.1345407188438568
## Attrib Platform=PC 2.6329740949584046
## Attrib Platform=PS 2.6723697776598834
## Attrib Platform=PS2 -0.8990560628652468
## Attrib Platform=PS3 -0.3816493881669787
## Attrib Platform=PS4 1.29815623946132
## Attrib Platform=PSP -0.5409902910067269
## Attrib Platform=PSV 2.2923083436785925
## Attrib Platform=Wii 1.2234392973681465
## Attrib Platform=WiiU -1.0407948071337665
## Attrib Platform=X360 -0.15004327480316818
## Attrib Platform=XB -0.391448898430216
## Attrib Platform=XOne -0.8711680520832835
## Attrib Genre=Action -1.684832454425986
## Attrib Genre=Adventure 0.849608071576424
## Attrib Genre=Fighting 0.8294140741621385
## Attrib Genre=Misc -1.1925307155707805
## Attrib Genre=Platform -0.7494531160104484
## Attrib Genre=Puzzle 1.9945413230837803
## Attrib Genre=Racing -0.03429866164689333
## Attrib Genre=Role-Playing 0.6119090495422186
## Attrib Genre=Shooter 4.818456701360979
## Attrib Genre=Simulation 0.42107182011339656
## Attrib Genre=Sports 1.5250647051423165
## Attrib Genre=Strategy -1.1886151280723827
## Attrib Rating=E 2.7458181808078916
## Attrib Rating=E10+ -0.20566236738485558
## Attrib Rating=M -0.6363701039171467
## Attrib Rating=missing -0.05778643014240878
## Attrib Rating=T -0.020261358954502047
## Attrib Critic_Score -1.4535644725411596
## Attrib Critic_Count 2.0825828466593603
## Attrib User_Score 4.3402766745895
## Attrib User_Count -2.9779517117196805
## Sigmoid Node 8
## Inputs Weights
## Threshold -0.7332750923422595
## Attrib Platform=3DS 1.4748455932669295
## Attrib Platform=DS 2.1316034325622284
## Attrib Platform=GBA 1.8354032252178547
## Attrib Platform=GC 1.8428455615091461
## Attrib Platform=PC 0.22377291587173867
## Attrib Platform=PS -1.6319588598161008
## Attrib Platform=PS2 0.7460321100796518
## Attrib Platform=PS3 1.119303183855632
## Attrib Platform=PS4 -0.7073178548686017
## Attrib Platform=PSP 1.2865160424858932
## Attrib Platform=PSV -0.6174784024958613
## Attrib Platform=Wii -0.1690918222325477
## Attrib Platform=WiiU 2.038836967014555
## Attrib Platform=X360 1.2243800420785513
## Attrib Platform=XB 0.2263614969417155
## Attrib Platform=XOne -0.2230554066918485
## Attrib Genre=Action 2.8351311325809623
## Attrib Genre=Adventure -1.0224304134406008
## Attrib Genre=Fighting -1.135778061981006
## Attrib Genre=Misc 1.874952894102842
## Attrib Genre=Platform 1.557703886570885
## Attrib Genre=Puzzle 2.924157976672388
## Attrib Genre=Racing -0.10200566526553492
## Attrib Genre=Role-Playing -0.8449824016506784
## Attrib Genre=Shooter 1.2822132488568325
## Attrib Genre=Simulation 0.05050060455718715
## Attrib Genre=Sports 0.5373515904346136
## Attrib Genre=Strategy -0.36745056350102406
## Attrib Rating=E -1.151733263884495
## Attrib Rating=E10+ -0.941420241103331
## Attrib Rating=M -0.4111568491560629
## Attrib Rating=missing 3.205245769206807
## Attrib Rating=T 1.674166587029144
## Attrib Critic_Score -2.3833641161535337
## Attrib Critic_Count -1.4396074074721683
## Attrib User_Score 2.5994549981912223
## Attrib User_Count -10.259761853509097
## Sigmoid Node 9
## Inputs Weights
## Threshold -0.6942609415310941
## Attrib Platform=3DS 0.5963075040965643
## Attrib Platform=DS 0.25395239651396423
## Attrib Platform=GBA 0.7699185054656627
## Attrib Platform=GC 0.436377340042472
## Attrib Platform=PC 0.03550011697897111
## Attrib Platform=PS 1.2536734738998259
## Attrib Platform=PS2 0.668380367524921
## Attrib Platform=PS3 0.871804486419917
## Attrib Platform=PS4 0.4900240022095826
## Attrib Platform=PSP 1.2843490089573057
## Attrib Platform=PSV 0.9408829790814759
## Attrib Platform=Wii -0.4125634849813735
## Attrib Platform=WiiU 0.5300924782576475
## Attrib Platform=X360 0.5150553771223025
## Attrib Platform=XB 0.8479800457452
## Attrib Platform=XOne 1.027976890256231
## Attrib Genre=Action 0.554119780288238
## Attrib Genre=Adventure 1.7219821798324297
## Attrib Genre=Fighting 0.07000898983735938
## Attrib Genre=Misc 0.5941673717115803
## Attrib Genre=Platform 0.700835014881778
## Attrib Genre=Puzzle 0.5940564249691315
## Attrib Genre=Racing 0.8786424033831166
## Attrib Genre=Role-Playing 0.30297405121913706
## Attrib Genre=Shooter 0.8891130324386513
## Attrib Genre=Simulation 0.8995259116597583
## Attrib Genre=Sports 0.024763838240735286
## Attrib Genre=Strategy -0.09496643058461152
## Attrib Rating=E 0.4462950484099711
## Attrib Rating=E10+ 0.5613684436613713
## Attrib Rating=M 0.2652938649441458
## Attrib Rating=missing 0.5323828534959376
## Attrib Rating=T 0.3203830198472731
## Attrib Critic_Score -0.028034462643720316
## Attrib Critic_Count 0.20648777095682344
## Attrib User_Score 0.10578576282952644
## Attrib User_Count -14.6779057816387
## Sigmoid Node 10
## Inputs Weights
## Threshold -0.6178356357047536
## Attrib Platform=3DS 1.2804789866197117
## Attrib Platform=DS -0.9143771711251695
## Attrib Platform=GBA 1.2037606977260502
## Attrib Platform=GC -0.526000252420441
## Attrib Platform=PC 1.2634592240228426
## Attrib Platform=PS -0.7416039518055499
## Attrib Platform=PS2 0.45137187081421126
## Attrib Platform=PS3 0.7720093066635556
## Attrib Platform=PS4 -0.1436027218592678
## Attrib Platform=PSP 1.3136031765437002
## Attrib Platform=PSV 2.38986892238754
## Attrib Platform=Wii 0.35196174972673455
## Attrib Platform=WiiU -0.9722208277628407
## Attrib Platform=X360 -0.79408608584097
## Attrib Platform=XB 1.9353794540712235
## Attrib Platform=XOne 1.2140387619937134
## Attrib Genre=Action 0.555147489524961
## Attrib Genre=Adventure -0.47214601961704644
## Attrib Genre=Fighting 0.07332381321058591
## Attrib Genre=Misc 1.3486159838609388
## Attrib Genre=Platform 1.0101011091285292
## Attrib Genre=Puzzle 1.2842694206769818
## Attrib Genre=Racing -0.948595587115915
## Attrib Genre=Role-Playing 0.4872280499891094
## Attrib Genre=Shooter 0.9357126845181148
## Attrib Genre=Simulation -0.5802244233258743
## Attrib Genre=Sports 1.34322741796588
## Attrib Genre=Strategy 0.708868517190085
## Attrib Rating=E 0.30014683602022924
## Attrib Rating=E10+ 1.6046884706798858
## Attrib Rating=M 0.3430613400875553
## Attrib Rating=missing -0.38161822782347044
## Attrib Rating=T -0.11377723324681879
## Attrib Critic_Score 0.35240204313775775
## Attrib Critic_Count -0.38579797490976575
## Attrib User_Score 0.5598929456926385
## Attrib User_Count -8.203874939793188
## Sigmoid Node 11
## Inputs Weights
## Threshold -0.7053644742505044
## Attrib Platform=3DS -0.36821573329682683
## Attrib Platform=DS -0.5606243391151641
## Attrib Platform=GBA 0.931140248851685
## Attrib Platform=GC 0.5751698037815818
## Attrib Platform=PC 0.8234513136917345
## Attrib Platform=PS 0.27728850366122254
## Attrib Platform=PS2 -0.5207732635129538
## Attrib Platform=PS3 0.25522062976192766
## Attrib Platform=PS4 1.6800533183431283
## Attrib Platform=PSP 2.2312458456189597
## Attrib Platform=PSV 0.9186464870982249
## Attrib Platform=Wii 0.1845209343657597
## Attrib Platform=WiiU 1.492374989278165
## Attrib Platform=X360 1.6975998460101744
## Attrib Platform=XB 1.0296681260918852
## Attrib Platform=XOne -0.5098062107798353
## Attrib Genre=Action -0.46511821111690443
## Attrib Genre=Adventure 1.3385737396159905
## Attrib Genre=Fighting 2.9918040673745416
## Attrib Genre=Misc -0.6701434464749003
## Attrib Genre=Platform 1.7854369002191524
## Attrib Genre=Puzzle -0.7557896375060085
## Attrib Genre=Racing 1.7060741270707578
## Attrib Genre=Role-Playing 1.598850562074154
## Attrib Genre=Shooter -0.10468523249785078
## Attrib Genre=Simulation 1.4119294836049359
## Attrib Genre=Sports -1.8811410699468383
## Attrib Genre=Strategy 0.35910499425149345
## Attrib Rating=E 1.7924696460438068
## Attrib Rating=E10+ 0.14572088562313357
## Attrib Rating=M -1.1919981594708744
## Attrib Rating=missing 0.5769994248693907
## Attrib Rating=T 0.9041291462743687
## Attrib Critic_Score 2.831098638090609
## Attrib Critic_Count -4.594343041189037
## Attrib User_Score -0.6765816055207797
## Attrib User_Count -6.032973685028651
## Sigmoid Node 12
## Inputs Weights
## Threshold -0.7101869627418305
## Attrib Platform=3DS -2.655807595874827
## Attrib Platform=DS 0.5957474517282286
## Attrib Platform=GBA -0.0556334416307421
## Attrib Platform=GC 0.5860478802225317
## Attrib Platform=PC 12.92126939602982
## Attrib Platform=PS -0.6058803798187727
## Attrib Platform=PS2 0.40339835047352507
## Attrib Platform=PS3 1.4778891831964094
## Attrib Platform=PS4 -3.1353194373181315
## Attrib Platform=PSP -1.6280238254707868
## Attrib Platform=PSV -2.006547228653973
## Attrib Platform=Wii 0.1883439493062121
## Attrib Platform=WiiU 1.8588328969212102
## Attrib Platform=X360 1.3821738862995478
## Attrib Platform=XB 1.0525794015670635
## Attrib Platform=XOne -0.2305809560039546
## Attrib Genre=Action 1.406251753746359
## Attrib Genre=Adventure -0.34586383132576504
## Attrib Genre=Fighting 0.5221706413249019
## Attrib Genre=Misc -0.6707689832925511
## Attrib Genre=Platform 1.9886549193517293
## Attrib Genre=Puzzle 1.8669752840882199
## Attrib Genre=Racing 2.344555890002001
## Attrib Genre=Role-Playing -0.10441245267291717
## Attrib Genre=Shooter 0.31441212664028717
## Attrib Genre=Simulation -0.11933220990616772
## Attrib Genre=Sports 1.765999633001941
## Attrib Genre=Strategy -1.6117459732561465
## Attrib Rating=E 1.4853315526073594
## Attrib Rating=E10+ 1.5301816594945599
## Attrib Rating=M 3.316140182091462
## Attrib Rating=missing -0.3193810675751383
## Attrib Rating=T -3.9093982548828348
## Attrib Critic_Score -6.0836221257760466
## Attrib Critic_Count -3.1630282172385225
## Attrib User_Score 1.5998834872138854
## Attrib User_Count -13.853764622622355
## Sigmoid Node 13
## Inputs Weights
## Threshold -0.5040637225651712
## Attrib Platform=3DS -1.8148252495585913
## Attrib Platform=DS -2.0143667055894685
## Attrib Platform=GBA 0.8790819418017929
## Attrib Platform=GC -0.9092421079433944
## Attrib Platform=PC 0.8195307145324093
## Attrib Platform=PS -0.19416696762645452
## Attrib Platform=PS2 2.343293971538373
## Attrib Platform=PS3 2.693687716622662
## Attrib Platform=PS4 2.6920237943511607
## Attrib Platform=PSP 2.5758868699044664
## Attrib Platform=PSV 2.1028854154724987
## Attrib Platform=Wii -3.3986441397477734
## Attrib Platform=WiiU 0.5583957469279659
## Attrib Platform=X360 1.5338805460123426
## Attrib Platform=XB -1.8158802073173461
## Attrib Platform=XOne 1.2618141362576125
## Attrib Genre=Action -0.22785512883136266
## Attrib Genre=Adventure 0.4651917360447645
## Attrib Genre=Fighting -0.5014586874285917
## Attrib Genre=Misc 3.801157347853518
## Attrib Genre=Platform -1.661301050987903
## Attrib Genre=Puzzle -1.0275428584652577
## Attrib Genre=Racing -0.8368491322555952
## Attrib Genre=Role-Playing 1.7983338469832064
## Attrib Genre=Shooter -0.7546933984330143
## Attrib Genre=Simulation 1.5714877280303623
## Attrib Genre=Sports 1.7794901154999065
## Attrib Genre=Strategy 0.7681019530475391
## Attrib Rating=E 2.670534711689728
## Attrib Rating=E10+ -1.5312452121429665
## Attrib Rating=M 0.8403080152375223
## Attrib Rating=missing 1.0090421017014701
## Attrib Rating=T -1.4143014297626166
## Attrib Critic_Score -5.471939706137484
## Attrib Critic_Count 5.680054139357675
## Attrib User_Score 2.6050904852887076
## Attrib User_Count -4.289837192135473
## Sigmoid Node 14
## Inputs Weights
## Threshold -0.6313058502857144
## Attrib Platform=3DS 1.4629273680256074
## Attrib Platform=DS -0.05327984239295333
## Attrib Platform=GBA -1.4405698314663264
## Attrib Platform=GC -0.37615040674397066
## Attrib Platform=PC -0.18593950691525915
## Attrib Platform=PS 2.302494322129355
## Attrib Platform=PS2 2.4677774930527296
## Attrib Platform=PS3 1.2841121364757546
## Attrib Platform=PS4 0.46461042682115045
## Attrib Platform=PSP 0.592110502454173
## Attrib Platform=PSV 0.30672330751401655
## Attrib Platform=Wii -0.65844924068544
## Attrib Platform=WiiU -0.09527739252111518
## Attrib Platform=X360 0.1726312363604453
## Attrib Platform=XB 1.2620920460996277
## Attrib Platform=XOne 1.1022129846021376
## Attrib Genre=Action 0.9804517527213824
## Attrib Genre=Adventure -1.1709567105006986
## Attrib Genre=Fighting 2.1110238615189667
## Attrib Genre=Misc -2.0875352811063217
## Attrib Genre=Platform -0.1063440113702056
## Attrib Genre=Puzzle -1.5854024303032512
## Attrib Genre=Racing 0.40729968809651873
## Attrib Genre=Role-Playing 2.934664195799592
## Attrib Genre=Shooter 1.7052177515015263
## Attrib Genre=Simulation 1.9789609671618027
## Attrib Genre=Sports -1.6653577608137025
## Attrib Genre=Strategy 2.7039444924113436
## Attrib Rating=E 1.1667023851477971
## Attrib Rating=E10+ 0.2673304202525577
## Attrib Rating=M -0.5810344990595349
## Attrib Rating=missing 1.2831620539010495
## Attrib Rating=T -0.14407976626218716
## Attrib Critic_Score -1.2393579948577196
## Attrib Critic_Count -1.355949672469945
## Attrib User_Score -1.1081222811713722
## Attrib User_Count -7.004275736733326
## Sigmoid Node 15
## Inputs Weights
## Threshold -0.8107075833591353
## Attrib Platform=3DS 2.6572231815052403
## Attrib Platform=DS 2.0955579396193476
## Attrib Platform=GBA -1.760472220908768
## Attrib Platform=GC -1.1706980098190014
## Attrib Platform=PC -0.9033004127530642
## Attrib Platform=PS -0.20499430787551415
## Attrib Platform=PS2 0.5872156336445715
## Attrib Platform=PS3 1.3858057682179217
## Attrib Platform=PS4 0.17162106190509577
## Attrib Platform=PSP -0.7826321825377982
## Attrib Platform=PSV 2.1198826128691235
## Attrib Platform=Wii 1.2057937082635573
## Attrib Platform=WiiU 1.572331438874569
## Attrib Platform=X360 1.9268545832036033
## Attrib Platform=XB 0.8438617751324926
## Attrib Platform=XOne 1.9243247095470128
## Attrib Genre=Action 0.9435720320329288
## Attrib Genre=Adventure -0.3787823001136217
## Attrib Genre=Fighting 0.901359448413117
## Attrib Genre=Misc 2.6070706207695657
## Attrib Genre=Platform 2.036721140736888
## Attrib Genre=Puzzle -0.7612818056590597
## Attrib Genre=Racing 0.46131614991761355
## Attrib Genre=Role-Playing -1.2409183774334231
## Attrib Genre=Shooter 2.1239367579872788
## Attrib Genre=Simulation -0.06790786587087647
## Attrib Genre=Sports 0.1102466203211172
## Attrib Genre=Strategy 1.3868322528527828
## Attrib Rating=E 1.692276254673329
## Attrib Rating=E10+ 1.1351371265152064
## Attrib Rating=M -0.9857077242383918
## Attrib Rating=missing 0.7208686911677442
## Attrib Rating=T -0.03922569805142826
## Attrib Critic_Score 4.435146607411989
## Attrib Critic_Count -4.827290736013087
## Attrib User_Score 3.42234344947838
## Attrib User_Count -3.6584282395611374
## Sigmoid Node 16
## Inputs Weights
## Threshold -0.7379772289707649
## Attrib Platform=3DS 2.3094347761171523
## Attrib Platform=DS 0.8031097124926416
## Attrib Platform=GBA -1.7564645827700747
## Attrib Platform=GC 0.010155747811853872
## Attrib Platform=PC -0.13687439839895332
## Attrib Platform=PS -0.43541736851895396
## Attrib Platform=PS2 1.4163975368684674
## Attrib Platform=PS3 1.9327297586948877
## Attrib Platform=PS4 0.24872811399631606
## Attrib Platform=PSP -1.4679613782765653
## Attrib Platform=PSV 2.5160169819473692
## Attrib Platform=Wii 0.020527533746748455
## Attrib Platform=WiiU 0.35854665129698926
## Attrib Platform=X360 1.6303395051417167
## Attrib Platform=XB 1.9422598240609263
## Attrib Platform=XOne 0.26678158318904294
## Attrib Genre=Action -0.5977106726740545
## Attrib Genre=Adventure -0.6148436676092004
## Attrib Genre=Fighting 2.378667152118756
## Attrib Genre=Misc 1.247841005463612
## Attrib Genre=Platform 3.0978604372825673
## Attrib Genre=Puzzle 0.06615195805668528
## Attrib Genre=Racing -0.4528906168601716
## Attrib Genre=Role-Playing -1.4679612836120222
## Attrib Genre=Shooter 2.121711870696616
## Attrib Genre=Simulation -0.5864678093327398
## Attrib Genre=Sports 2.455785590530606
## Attrib Genre=Strategy -0.9705992982360405
## Attrib Rating=E -0.05405946506054782
## Attrib Rating=E10+ -1.25574805460996
## Attrib Rating=M -0.34431263763149306
## Attrib Rating=missing 0.761225779465465
## Attrib Rating=T 2.974485637832724
## Attrib Critic_Score -1.9315466271806614
## Attrib Critic_Count -0.9162744134296475
## Attrib User_Score -2.2796298675409523
## Attrib User_Count -8.270666674976317
## Sigmoid Node 17
## Inputs Weights
## Threshold -0.6350749005510964
## Attrib Platform=3DS -0.3950023083273609
## Attrib Platform=DS 1.2056617852407983
## Attrib Platform=GBA 0.2819650305829227
## Attrib Platform=GC 0.22794924950280665
## Attrib Platform=PC -0.7459090767497283
## Attrib Platform=PS -0.5672522294923418
## Attrib Platform=PS2 1.2246486647562471
## Attrib Platform=PS3 0.3243210500441006
## Attrib Platform=PS4 -1.5463305356680852
## Attrib Platform=PSP 1.928163376677261
## Attrib Platform=PSV 3.503901611085354
## Attrib Platform=Wii 1.254879119948876
## Attrib Platform=WiiU 1.7088214329129625
## Attrib Platform=X360 -1.5924554663526342
## Attrib Platform=XB 0.04997209588441949
## Attrib Platform=XOne 2.2071980964718816
## Attrib Genre=Action 1.8039342217046221
## Attrib Genre=Adventure 4.413992289248062
## Attrib Genre=Fighting -0.11929010981560148
## Attrib Genre=Misc -1.2370655233375523
## Attrib Genre=Platform -0.5048561894108922
## Attrib Genre=Puzzle 1.6348556080941588
## Attrib Genre=Racing -0.5692385178634677
## Attrib Genre=Role-Playing -0.11613025790293993
## Attrib Genre=Shooter -0.46656366323463516
## Attrib Genre=Simulation -0.5968765350607996
## Attrib Genre=Sports 1.0641280602838856
## Attrib Genre=Strategy 1.3752263889767429
## Attrib Rating=E 0.8294178356899463
## Attrib Rating=E10+ -0.16930891956112532
## Attrib Rating=M -0.09228570444517652
## Attrib Rating=missing 0.2582787653971765
## Attrib Rating=T 1.033842692227996
## Attrib Critic_Score 1.8183726314042084
## Attrib Critic_Count 1.6049322021881838
## Attrib User_Score 0.05647580017536152
## Attrib User_Count -8.169040851967305
## Sigmoid Node 18
## Inputs Weights
## Threshold -0.9450695119891854
## Attrib Platform=3DS 0.41815825198478945
## Attrib Platform=DS -0.2106231402405922
## Attrib Platform=GBA 1.1553353001987547
## Attrib Platform=GC 1.0130444893315758
## Attrib Platform=PC -0.7513378945563963
## Attrib Platform=PS 0.0709123845597251
## Attrib Platform=PS2 1.0675306553357022
## Attrib Platform=PS3 1.7861454234654304
## Attrib Platform=PS4 1.9836568683820577
## Attrib Platform=PSP 1.011919969185461
## Attrib Platform=PSV -0.02340079205562146
## Attrib Platform=Wii 1.3271667713312263
## Attrib Platform=WiiU -0.46062401117538043
## Attrib Platform=X360 1.5760917340452867
## Attrib Platform=XB 0.9377960923870591
## Attrib Platform=XOne 2.2064850302668333
## Attrib Genre=Action 1.1652114838283956
## Attrib Genre=Adventure -0.6377202160064129
## Attrib Genre=Fighting -0.3797545352276567
## Attrib Genre=Misc 0.21959026628111564
## Attrib Genre=Platform 1.6718820665953693
## Attrib Genre=Puzzle 2.1796440653618
## Attrib Genre=Racing 1.2938873069594177
## Attrib Genre=Role-Playing 0.7095399734231067
## Attrib Genre=Shooter 1.1196938988127758
## Attrib Genre=Simulation 0.8363250857458256
## Attrib Genre=Sports 0.6083735814671088
## Attrib Genre=Strategy 0.4956359742710795
## Attrib Rating=E 0.49192575633812313
## Attrib Rating=E10+ 0.12082271338645423
## Attrib Rating=M 1.1547648084001758
## Attrib Rating=missing -0.4229830169565915
## Attrib Rating=T 1.501182048754668
## Attrib Critic_Score -0.3127728906287192
## Attrib Critic_Count 0.13154541586099122
## Attrib User_Score 1.2073522543574844
## Attrib User_Count -16.08908157139032
## Sigmoid Node 19
## Inputs Weights
## Threshold -0.5808407298921427
## Attrib Platform=3DS 1.0598530520853688
## Attrib Platform=DS 1.5415769447935601
## Attrib Platform=GBA 0.0905463763299941
## Attrib Platform=GC 2.216248582225177
## Attrib Platform=PC -1.6015144066078741
## Attrib Platform=PS 3.9083765795394796
## Attrib Platform=PS2 -0.4120869367613734
## Attrib Platform=PS3 -2.4055467029361948
## Attrib Platform=PS4 0.18960573064668215
## Attrib Platform=PSP 0.17335559498596761
## Attrib Platform=PSV 1.2631374889622191
## Attrib Platform=Wii 1.152247823764874
## Attrib Platform=WiiU 1.1969411410170314
## Attrib Platform=X360 0.3264846407506086
## Attrib Platform=XB -0.2955677070161061
## Attrib Platform=XOne 0.4521044281549024
## Attrib Genre=Action -0.7328516893259439
## Attrib Genre=Adventure 0.2977604567439386
## Attrib Genre=Fighting 0.6087987044930241
## Attrib Genre=Misc 4.184332392562179
## Attrib Genre=Platform 0.5464684563128378
## Attrib Genre=Puzzle 0.30468071307417066
## Attrib Genre=Racing 0.8779003667202093
## Attrib Genre=Role-Playing 1.0465950653840226
## Attrib Genre=Shooter -0.749337496406182
## Attrib Genre=Simulation 0.9920552322732776
## Attrib Genre=Sports -1.1464858959261908
## Attrib Genre=Strategy -0.05955537914717704
## Attrib Rating=E -1.399765844563152
## Attrib Rating=E10+ 0.6762185274294912
## Attrib Rating=M -0.32193261661276484
## Attrib Rating=missing 1.1816581930795564
## Attrib Rating=T 1.8553730090727274
## Attrib Critic_Score -1.240921372076429
## Attrib Critic_Count -2.5143624688648094
## Attrib User_Score -1.7697697609610297
## Attrib User_Count -3.2974513307895337
## Class
## Input
## Node 0
Evaluation:
target_variable <- 'NA_Sales'
# Get predictions from the MLP model
test_predictions <- predict(model_default, test_set)
# Calculate performance metrics
test_performance <- postResample(test_predictions, test_set[[target_variable]])
# Convert to data frame
performance_df <- data.frame(
RMSE = test_performance[1],
Rsquared = test_performance[2],
MAE = test_performance[3]
)
# Display the data frame as a table
print(performance_df)
## RMSE Rsquared MAE
## RMSE 0.4684872 0.2348866 0.3260087
i.Build and evaluate ksvm models for numeric prediction with the video game sales data (imported and prepared in 1B).
#target variable
kvsm <- ksvm(NA_Sales ~ .,data = train_set)
kvsm
## Support Vector Machine object of class "ksvm"
##
## SV type: eps-svr (regression)
## parameter : epsilon = 0.1 cost C = 1
##
## Gaussian Radial Basis kernel function.
## Hyperparameter : sigma = 0.127875279768244
##
## Number of Support Vectors : 3192
##
## Objective Function Value : -1484.829
## Training error : 0.614263
Evaluation:
test_predictions_kvsm<- predict(kvsm, test_set)
# Calculate performance metrics
test_performance_kvsm <- postResample(test_predictions_kvsm, test_set[[target_variable]])
# Convert to data frame
performance_df_kvsm <- data.frame(
RMSE = test_performance_kvsm[1],
Rsquared = test_performance_kvsm[2],
MAE = test_performance_kvsm[3]
)
# Display the data frame as a table
print(performance_df_kvsm)
## RMSE Rsquared MAE
## RMSE 0.4257648 0.4448585 0.2192906
kernel_kvsm <- ksvm(NA_Sales ~ ., data = train_set, kernel = "rbfdot")
kernel_kvsm
## Support Vector Machine object of class "ksvm"
##
## SV type: eps-svr (regression)
## parameter : epsilon = 0.1 cost C = 1
##
## Gaussian Radial Basis kernel function.
## Hyperparameter : sigma = 0.126088152389135
##
## Number of Support Vectors : 3196
##
## Objective Function Value : -1486.752
## Training error : 0.615589
Evaluate:
# Evaluate the model performance on the training set
train_predictions <- predict(kernel_kvsm, train_set)
train_performance <- postResample(pred = train_predictions, obs = train_set$NA_Sales)
# Evaluate the model performance on the testing set
test_predictions <- predict(kernel_kvsm, test_set)
test_performance <- postResample(pred = test_predictions, obs = test_set$NA_Sales)
# Print performance metrics
cat("Training Performance:\n")
## Training Performance:
print(train_performance)
## RMSE Rsquared MAE
## 0.3758041 0.4712751 0.1894509
cat("Testing Performance:\n")
## Testing Performance:
print(test_performance)
## RMSE Rsquared MAE
## 0.4258504 0.4448389 0.2192921
cv_kvsm <- ksvm(NA_Sales ~ ., data = train_set, kernel = "rbfdot", C = 10)
cv_kvsm
## Support Vector Machine object of class "ksvm"
##
## SV type: eps-svr (regression)
## parameter : epsilon = 0.1 cost C = 10
##
## Gaussian Radial Basis kernel function.
## Hyperparameter : sigma = 0.130914236218174
##
## Number of Support Vectors : 3311
##
## Objective Function Value : -11885.35
## Training error : 0.428585
Evaluation:
# Predict and evaluate on the training set
train_predictions_cv_kvsm<- predict(cv_kvsm, train_set)
train_performance_cv_kvsm<- postResample(train_predictions_cv_kvsm, train_set$NA_Sales)
# Predict and evaluate on the testing set
test_predictions_cv_kvsm <- predict(cv_kvsm, test_set)
test_performance_cv_kvsm <- postResample(test_predictions_cv_kvsm, test_set$NA_Sales)
# Combine training and testing performance metrics into df
performance_metrics_cv_kvsm <- data.frame(
Dataset = c("Training", "Testing"),
RMSE = c(train_performance_cv_kvsm[1], test_performance_cv_kvsm[1]),
Rsquared = c(train_performance_cv_kvsm[2], test_performance_cv_kvsm[2]),
MAE = c(train_performance_cv_kvsm[3], test_performance_cv_kvsm[3])
)
# kable table
kable(performance_metrics_cv_kvsm, caption = "KSVM Model Performance Metrics")
Dataset | RMSE | Rsquared | MAE |
---|---|---|---|
Training | 0.3135700 | 0.6009569 | 0.1545275 |
Testing | 0.3943748 | 0.4618584 | 0.2186985 |
ibk_default <- IBk(NA_Sales ~ ., data = train_set)
ibk_default
## IB1 instance-based classifier
## using 1 nearest neighbour(s) for classification
# Evaluate the model performance on the training set
train_predictions <- predict(ibk_default, train_set)
train_performance <- postResample(pred = train_predictions, obs = train_set$NA_Sales)
# Evaluate the model performance on the testing set
test_predictions <- predict(ibk_default, test_set)
test_performance <- postResample(pred = test_predictions, obs = test_set$NA_Sales)
# Print performance metrics
cat("Training Performance:\n")
## Training Performance:
print(train_performance)
## RMSE Rsquared MAE
## 0.0107533646 0.9994958563 0.0003489419
cat("Testing Performance:\n")
## Testing Performance:
print(test_performance)
## RMSE Rsquared MAE
## 0.5637813 0.1502960 0.3174488
ibk_model_k5 <- IBk(NA_Sales ~ ., data = train_set, control = Weka_control(K = 5))
ibk_model_k5
## IB1 instance-based classifier
## using 5 nearest neighbour(s) for classification
# Evaluate the model performance on the training set
train_predictions <- predict(ibk_model_k5, train_set)
train_performance <- postResample(pred = train_predictions, obs = train_set$NA_Sales)
# Evaluate the model performance on the testing set
test_predictions <- predict(ibk_model_k5, test_set)
test_performance <- postResample(pred = test_predictions, obs = test_set$NA_Sales)
# Print performance metrics
cat("Training Performance with K =", 5, ":\n")
## Training Performance with K = 5 :
print(train_performance)
## RMSE Rsquared MAE
## 0.3529768 0.4606207 0.2133044
cat("Testing Performance with K =", 5, ":\n")
## Testing Performance with K = 5 :
print(test_performance)
## RMSE Rsquared MAE
## 0.4616865 0.2420356 0.2691969
ibk_weighted <- IBk(NA_Sales ~ ., data = train_set, control = Weka_control(I = TRUE))
ibk_weighted
## IB1 instance-based classifier
## using 1 inverse-distance-weighted nearest neighbour(s) for classification
Evaulate:
# Evaluate the model performance on the training set
train_predictions <- predict(ibk_weighted, train_set)
train_performance <- postResample(pred = train_predictions, obs = train_set$NA_Sales)
# Evaluate the model performance on the testing set
test_predictions <- predict(ibk_weighted, test_set)
test_performance <- postResample(pred = test_predictions, obs = test_set$NA_Sales)
# Print performance metrics
cat("Training Performance with I= TRUE:\n")
## Training Performance with I= TRUE:
print(train_performance)
## RMSE Rsquared MAE
## 0.0107533646 0.9994958563 0.0003489419
cat("Testing Performance with I = TRUE:\n")
## Testing Performance with I = TRUE:
print(test_performance)
## RMSE Rsquared MAE
## 0.5637813 0.1502960 0.3174488
ibk_auto_k <- IBk(NA_Sales ~ ., data = train_set, control = Weka_control(X = TRUE))
ibk_auto_k
## IB1 instance-based classifier
## using 1 nearest neighbour(s) for classification
Evauluate:
# Evaluate the model performance on the training set
train_predictions <- predict(ibk_auto_k, train_set)
train_performance <- postResample(pred = train_predictions, obs = train_set$NA_Sales)
# Evaluate the model performance on the testing set
test_predictions <- predict(ibk_auto_k, test_set)
test_performance <- postResample(pred = test_predictions, obs = test_set$NA_Sales)
# Print performance metrics
cat("Training Performance with Automatic K Selection:\n")
## Training Performance with Automatic K Selection:
print(train_performance)
## RMSE Rsquared MAE
## 0.0107533646 0.9994958563 0.0003489419
cat("Testing Performance with Automatic K Selection:\n")
## Testing Performance with Automatic K Selection:
print(test_performance)
## RMSE Rsquared MAE
## 0.5637813 0.1502960 0.3174488
A. Define a named function (e.g., cv_function) for cross-validation evaluation of classification or numeric prediction models with df, target, nFolds, seedVal, method and metrics_list for input.
cv_function <- function(df, target, nFolds, seedVal, method, metrics_list) {
set.seed(seedVal)
folds = createFolds(df[[target]], k = nFolds, list = TRUE, returnTrain = FALSE)
cv_results <- lapply(seq_along(folds), function(fold_number) {
fold_indexes = folds[[fold_number]]
train_data <- df[-fold_indexes, ]
test_data <- df[fold_indexes, ]
# Model training
if (method == "MLP") {
# Use the correct function name from RWeka
model <- MLP(as.formula(paste(target, "~ .")), data = train_data)
} else if (method == "ksvm") {
model <- ksvm(as.formula(paste(target, "~ .")), data = train_data)
} else if (method == "IBk") {
model <- IBk(as.formula(paste(target, "~ .")), data = train_data)
} else {
stop("Unsupported method")
}
predictions <- predict(model, test_data)
# Performance evaluation
metrics_results <- sapply(metrics_list, function(metric) {
metric_fun <- match.fun(metric)
metric_fun(test_data[[target]], predictions)
})
return(metrics_results)
})
# Convert list to matrix for fold-by-fold results
cv_matrix <- do.call(cbind, cv_results)
colnames(cv_matrix) <- paste("Fold", 1:nFolds)
rownames(cv_matrix) <- metrics_list
# Aggregate results
cv_mean <- rowMeans(cv_matrix)
cv_sd <- apply(cv_matrix, 1, sd)
aggregate_results <- rbind(cv_mean, cv_sd)
rownames(aggregate_results) <- c("Mean", "SD")
# Return a list containing both fold-by-fold and aggregated results
return(list("Fold-by-Fold" = cv_matrix, "Aggregate" = aggregate_results))
}
# For MultilayerPerceptron
cv_results_mlp <- cv_function(df = train_set, target = "NA_Sales",
nFolds = 5, seedVal = 123, method = "MLP",
metrics_list = c("RMSE", "R2"))
cat("MLP Results:\n")
## MLP Results:
print(cv_results_mlp)
## $`Fold-by-Fold`
## Fold 1 Fold 2 Fold 3 Fold 4 Fold 5
## RMSE 0.4556454 0.4470677 0.4502537 0.5264746 0.4502859
## R2 0.2323416 0.1600384 0.2148854 0.1632362 0.2320536
##
## $Aggregate
## RMSE R2
## Mean 0.46594546 0.20051102
## SD 0.03397681 0.03620148
# For ksvm
cv_results_ksvm <- cv_function(df = train_set, target = "NA_Sales",
nFolds = 5, seedVal = 123, method = "ksvm",
metrics_list = c("RMSE", "R2"))
cat("KSVM Results:\n")
## KSVM Results:
print(cv_results_ksvm)
## $`Fold-by-Fold`
## Fold 1 Fold 2 Fold 3 Fold 4 Fold 5
## RMSE 0.4139262 0.3984619 0.4017311 0.3891748 0.3859094
## R2 0.3552798 0.3801191 0.3666509 0.3997972 0.3793127
##
## $Aggregate
## RMSE R2
## Mean 0.39784068 0.37623193
## SD 0.01108737 0.01666368
# For IBk
cv_results_ibk <- cv_function(df = train_set, target = "NA_Sales",
nFolds = 5, seedVal = 123, method = "IBk",
metrics_list = c("RMSE", "R2"))
cat("IBk Results:\n")
## IBk Results:
print(cv_results_ibk)
## $`Fold-by-Fold`
## Fold 1 Fold 2 Fold 3 Fold 4 Fold 5
## RMSE 0.5369817 0.5308002 0.5322643 0.5945839 0.5399703
## R2 0.1398998 0.1171319 0.1357560 0.0887774 0.0863841
##
## $Aggregate
## RMSE R2
## Mean 0.5469201 0.1135898
## SD 0.0268959 0.0252582
Increasing the cost parameter C from 1 to 10 resulted in noticeable improvements in the model’s performance. Specifically, the training RMSE decreased from 0.614263 to 0.3135700, and the Rsquared increased from 0.4712751 to 0.6009569, indicating a better fit to the training data. This change also benefited the test data, with the RMSE improving from 0.4257648 to 0.3943748 and the Rsquared increasing from 0.4448585 to 0.4618584. These numbers demonstrate that the model with a higher cost parameter was more accurate in predicting sales, suggesting a positive impact from allowing the model more complexity in defining the decision boundary.
However, an important consideration is the risk of overfitting, which could result from an excessively high C value. In this case, cross-validation provided a safeguard by offering a more comprehensive assessment of the model’s predictive power across different data subsets. The cross-validation results, with an average RMSE of 0.39784068 and an Rsquared of 0.37623193, confirm that the improvements from the increased cost parameter did not lead to overfitting, as the performance remained stable.
Regarding the sigma parameter for the Gaussian Radial Basis function, the changes were minimal and did not significantly impact the model’s performance. The sigma was altered slightly from 0.127875 to 0.126088 and then to 0.130914 with the cost increase. However, these small adjustments in sigma did not result in substantial changes in performance metrics. This suggests that the video game sales data might not be highly sensitive to this, or the sigma values tested were already close to optimal. The stability of the model against these minor variations is a good indicator that the model is robust with respect to the kernel function.
The baseline results was the default MLP. this yielded an RMSE of .468 and r squared of .235.
When the MLP model was adjusted to have two hidden layers with unspecified sizes (left for Weka to determine) and hyperparameters set to a learning rate l of 0.3, momentum, m of 0.2, and epochs n of 500, the performance improved. The RMSE decreased to 0.4327963, Rsquared increased to 0.3357142, and MAE lowered to 0.2614855. This improvement suggests that increasing the model’s complexity by adding an additional hidden layer and adjusting the learning parameters enabled to evaluate the model with more nuance aiding the accuracy.
Cross-validation results for the MLP model across 5 folds, with a mean RMSE of 0.46594546 and a mean Rsquared of 0.20051102, suggest that the model’s performance is moderately consistent across different data subsets. The standard deviations for RMSE and Rsquared were 0.03397681 and 0.03620148, respectively, indicating some variation in model performance across folds, which is not unusual in cross-validation analyses.
Despite these improvements, the model still needs to be checked for overfitting, as cross-validation indicates variability in performance, which could suggest the model is not generalizing as well as it could.
Building these models taught me that careful tuning of hyperparameters can significantly improve the performance of machine learning models. For instance, with the KSVM model, increasing the cost parameter ‘C’ allowed the model to pay more attention to classifying the training data correctly. This change led to a noticeable improvement in performance, reducing the RMSE and increasing the Rsquared, meaning the predictions were closer to the actual sales figures, and the model explained a greater proportion of the variance in the data.
With the MLP model, adding an extra hidden layer and fine-tuning the learning rate, momentum, and number of epochs made the model better at capturing the complex patterns in the data. This resulted in a lower RMSE and higher Rsquared, indicating more accurate predictions and better generalization. The cross-validation results highlighted that while our model is reasonably stable, there’s some variation in how it performs on different subsets of the data.
Our model adjustments have made our predictions more accurate, but we’ve also added complexity and potentially increased the computational resources needed. It’s a trade-off that has paid off in terms of accuracy but is something we need to monitor to ensure we’re not overfitting and our model remains practical for everyday use.