From cf46fb555fe7e804fe3a97c9b6f9a1bbec8a2290 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B8rn=20Sand=20Jensen?= <bjje@dtu.dk>
Date: Thu, 25 Jan 2024 13:05:41 +0100
Subject: [PATCH] Minor bug fixes

---
 .../Scripts/check_installation.py                   | 13 +++++++++++--
 exercises/02450Toolbox_Python/Scripts/ex1_5_4.py    |  3 +++
 exercises/02450Toolbox_Python/Scripts/ex1_5_5.py    |  6 ++++--
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/exercises/02450Toolbox_Python/Scripts/check_installation.py b/exercises/02450Toolbox_Python/Scripts/check_installation.py
index cc381d5..e5add52 100644
--- a/exercises/02450Toolbox_Python/Scripts/check_installation.py
+++ b/exercises/02450Toolbox_Python/Scripts/check_installation.py
@@ -1,5 +1,8 @@
 """ 
 This is a helper function which can help you debug the Python installation
+
+v20240125
+
 """
 import os
 import sklearn
@@ -11,14 +14,20 @@ print('------------------------------------------------------------------')
 print('Path of this file {}'.format(os.path.abspath(__file__)))
 print('Current working directory {}.'.format(pathlib.Path().resolve()))
 print('')
-print('The numpy version is{}.'.format(np.__version__))
+print('The numpy version is {}.'.format(np.__version__))
 print('The scikit-learn version is {}.'.format(sklearn.__version__))
-print('The Torch version is{}.'.format(torch.__version__))
+print('The torch version is{}.'.format(torch.__version__))
 
 """
 Check that the course specific tools can be imported 
 """
 import dtuimldmtools 
 print('The dtuimldmtools package {}.'.format(dtuimldmtools))
+
+"""
+Check that pandas can be imported (use in ex1)
+"""
+import pandas 
+print('The panda package {}.'.format(pandas.__version__))
 print('------------------------------------------------------------------')
 
diff --git a/exercises/02450Toolbox_Python/Scripts/ex1_5_4.py b/exercises/02450Toolbox_Python/Scripts/ex1_5_4.py
index f853fb3..9377c56 100644
--- a/exercises/02450Toolbox_Python/Scripts/ex1_5_4.py
+++ b/exercises/02450Toolbox_Python/Scripts/ex1_5_4.py
@@ -82,6 +82,8 @@ plt.title("Iris regression problem")
 plt.plot(X_r[:, i], y_r, "o")
 plt.xlabel(attributeNames_r[i])
 plt.ylabel(targetName_r)
+plt.show()
+
 # Consider if you see a relationship between the predictor variable on the
 # x-axis (the variable from X) and the target variable on the y-axis (the
 # variable y). Could you draw a straight line through the data points for
@@ -89,3 +91,4 @@ plt.ylabel(targetName_r)
 # Note that, when i is 3, 4, or 5, the x-axis is based on a binary
 # variable, in which case a scatter plot is not as such the best option for
 # visulizing the information.
+
diff --git a/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py b/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py
index 052b3ab..e1b6d01 100644
--- a/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py
+++ b/exercises/02450Toolbox_Python/Scripts/ex1_5_5.py
@@ -1,4 +1,5 @@
 ## exercise 1.5.5
+import importlib_resources
 import matplotlib.pyplot as plt
 import numpy as np
 
@@ -8,11 +9,12 @@ import pandas as pd
 # We start by defining the path to the file that we're we need to load.
 # Upon inspection, we saw that the messy_data.data was infact a file in the
 # format of a CSV-file with a ".data" extention instead.
-file_path = "../data/messy_data/messy_data.data"
+filename = importlib_resources.files("dtuimldmtools").joinpath("data/messy_data/messy_data.data")
+
 # First of we simply read the file in using readtable, however, we need to
 # tell the function that the file is tab-seperated. We also need to specify
 # that the header is in the second row:
-messy_data = pd.read_csv(file_path, sep="\t", header=1)
+messy_data = pd.read_csv(filename, sep="\t", header=1)
 # We also need to remove the added header line in the .data file which seems
 # to have included a shortend form the variables (check messy_data.head()):
 messy_data = messy_data.drop(messy_data.index[0])
-- 
GitLab