Python Forum
Question on None function in a machine learning algorithm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question on None function in a machine learning algorithm
#1
def evaluate_algorithm(dataset, algorithm, n_folds, *args):
	folds = cross_validation_split(dataset, n_folds)
	scores = list()
	for fold in folds:
		train_set = list(folds)
		train_set.remove(fold)
		train_set = sum(train_set, [])
		test_set = list()
		for row in fold:
			row_copy = list(row)
			test_set.append(row_copy)
			row_copy[-1] = None
		predicted = algorithm(train_set, test_set, *args)
		actual = [row[-1] for row in fold]
		rmse = rmse_metric(actual, predicted)
		scores.append(rmse)
	return scores
I was wondering if anyone could explain the for loop and what it does for the function? specifically why row_copy[-1] = None is necessary
Reply
#2
It appears that the last element of the row_copy list is being "removed" by setting it to None.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A class of machine learning programs Led_Zeppelin 0 466 Jul-13-2023, 01:17 PM
Last Post: Led_Zeppelin
Sad I'm stuck with the reinforcement learning function in my Code OskiLori 2 1,515 May-20-2023, 10:01 PM
Last Post: OskiLori
  Question on dir() function Soorya25 1 1,109 Jan-16-2023, 09:33 PM
Last Post: deanhystad
  Function not scriptable: Noob question kaega2 3 1,136 Aug-21-2022, 04:37 PM
Last Post: kaega2
  input function question barryjo 12 2,637 Jan-18-2022, 12:11 AM
Last Post: barryjo
Big Grin question about simple algorithm to my problem jamie_01 1 1,635 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  Learning python SyntaxError: 'return' outside function Grale1953 3 2,470 Aug-03-2020, 06:55 AM
Last Post: buran
  Question in python function problem saratha 1 1,428 Jul-08-2020, 04:56 PM
Last Post: jefsummers
  question about python3 print function jamie_01 5 2,599 May-25-2020, 09:58 AM
Last Post: pyzyx3qwerty
  Question about the groupby function new_to_python 7 3,136 Feb-09-2020, 07:52 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020