<jupyter_start><jupyter_text><jupyter_code>import math


class Task4:
	def __init__(self, data, y):
		self.data_list = data
		self.column_number = y
		self.mean = 0
		self.sigma = 0

	def calculate_mean(self):
		summation = 0
		for elements in self.data_list:
			summation += elements[self.column_number]
		self.mean = summation / len(self.data_list)
		return self.mean

	def calculate_sigma(self):
		if len(self.data_list) == 0:
			return 0
		summation = 0
		for elements in self.data_list:
			summation += ((elements[self.column_number] - self.mean) * (elements[self.column_number] - self.mean))
		self.sigma = math.sqrt(summation / (len(self.data_list)-1))
		return math.pow(self.sigma, 2)


def load_data_set(filename):
	input_file = open(filename, "r")
	print("⤵\n")    
	unique_labels = []
	dictionary = {}
	for line in input_file:
		row_list = (line.split(" "))
		row_list = list(filter(None, row_list))
		row_list = list(map(float, row_list))
		if row_list[-1] in dictionary:
			dictionary[row_list[-1]].append(row_list[0: -1])
		else:
			unique_labels.append(row_list[-1])
			dictionary[row_list[-1]] = [row_list[0: -1]]
	return dictionary, unique_labels


def main():
	file_path = input()
	dic, unique_labels = load_data_set(file_path)
	unique_labels = sorted(unique_labels)
	for label in range(0, len(unique_labels)):
		for dimension in range(0, len(dic[unique_labels[label]][0])):
			task4 = Task4(dic[unique_labels[label]], dimension)
			mean = task4.calculate_mean()
			sigma = task4.calculate_sigma()
			print("Class %d" % unique_labels[label], " dimension ", dimension + 1, " mean = %.2f" % mean, " variance = %.2f" % sigma)

main()


# ▶ Run and Enter ➜ data/yeast_training.txt
# or
# ▶ Run and Enter ➜ data/satellite_training.txt<jupyter_output>data/yeast_training.txt
⤵

Class 1  dimension  1  mean = 0.52  variance = 0.01
Class 1  dimension  2  mean = 0.54  variance = 0.01
Class 1  dimension  3  mean = 0.52  variance = 0.01
Class 1  dimension  4  mean = 0.41  variance = 0.03
Class 1  dimension  5  mean = 0.50  variance = 0.00
Class 1  dimension  6  mean = 0.00  variance = 0.00
Class 1  dimension  7  mean = 0.50  variance = 0.00
Class 1  dimension  8  mean = 0.24  variance = 0.00
Class 2  dimension  1  mean = 0.45  variance = 0.01
Class 2  dimension  2  mean = 0.45  variance = 0.01
Class 2  dimension  3  mean = 0.53  variance = 0.00
Class 2  dimension  4  mean = 0.23  variance = 0.01
Class 2  dimension  5  mean = 0.50  variance = 0.00
Class 2  dimension  6  mean = 0.00  variance = 0.00
Class 2  dimension  7  mean = 0.49  variance = 0.00
Class 2  dimension  8  mean = 0.33  variance = 0.02
Class 3  dimension  1  mean = 0.43  variance = 0.01
Class 3  dimension  2  mean = 0.48  variance = 0.01
Class 3  dimension  3  mean = 0.36  v[...]
{'fraction_non_alphanumeric': 0.12102601156069365, 'fraction_numerical': 0.06358381502890173, 'mean_word_length': 3.374407582938389, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '273409', 'license': 'MIT', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1046, 'n_words': 293, 'path': '02_PYTHON/04_Fitting_1D_Gaussian_to_data/Fitting_1D_Gaussian_to_data.ipynb', 'repo_name': 'milaan9/Machine_Learning_and_Deep_Learning', 'size': '2768'}