Skip to content
Snippets Groups Projects
Commit ab5be310 authored by bjje's avatar bjje
Browse files

Updated structure of lecture plan and file names (needs to be double checked)

parent d004d8ad
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 44 deletions
# Exercise 0.4.2 - using the VScode editor (ignore if you are not )
#
## Option I
# Standard python code will look like the 4 lines below
# and this is the way all scripts are
# displayed/implemented in this course
#
# To run it you need to press the run symbol or F5 or Ctrl+F5
#
a = 1
print(a)
b = a + 1
print(b)
#%%[markdown]
# ## Option II
# If you prefer, you can get an
# interactive experience in VScode if
# you use the #%% tag, e.g.
#%%[markdown]
# This is a cell you can run without running the rest of the code
# and get some pretty formatted output.
c = 2
print(c)
#%%[markdown]
# This is an other cell
# In the interactive mode you can even use markdown and include equations in teh output
# $$ b = c + \frac{1}{2} $$
#
# Note here the cell depends on the value of a variable from an other cell
# whcih must be run before this cell.
#
b = c + 1/2
print(b)
#%%[markdown]
# If you want this behavior you simply add the #%% or #%%[markdown] to the provided
# scripts in for you useful places.
#
# %%
......@@ -7,8 +7,8 @@
# now we can write 'np.sum(X)' instead of 'numpy.sum(X)'.
import numpy as np
# Remember you can mark a part of the code and press
# F9 to run that part alone.
# Remember you can use the #%% tag to define a cell
# and run this cell alone in interactive model, if you want.
# define variable a with numbers in the range from 0 to 7 (not inclusive)
a = np.arange(start=0, stop=7)
......@@ -22,3 +22,5 @@ c = np.arange(100, 95, -1)
d = np.arange(1.2, 1.9, 0.1)
e = np.pi * np.arange(0, 2.5, 0.5)
......@@ -11,6 +11,7 @@ filename = importlib_resources.files("dtuimldmtools").joinpath("data/iris.csv")
print("\nLocation of the iris.csv file: {}".format(filename))
# Load the iris.csv file using pandas
# Note you do not need to undersatnd the details of the panda package
df = pd.read_csv(filename)
# Pandas returns a dataframe, (df) which could be used for handling the data.
......
# exercise 3.1.4
# exercise 1.6.2
import importlib_resources
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
......
# exercise 3.1.4
# exercise 1.6.3
import importlib_resources
from sklearn.feature_extraction.text import CountVectorizer
......@@ -37,4 +37,4 @@ print()
print("Document-term matrix:")
print(X.toarray())
print()
print("Ran Exercise 3.1.3")
print("Ran Exercise 1.6.3")
# exercise 3.1.4
# exercise 1.6.4
import importlib_resources
# We'll use a widely used stemmer based:
......@@ -62,5 +62,5 @@ print()
print("Document-term matrix:")
print(X)
print()
print("Ran Exercise 3.1.4")
print("Ran Exercise 1.6.4")
print()
# exercise 3.1.5
# exercise 1.6.5
import numpy as np
import scipy.linalg as linalg
from ex1_6_4 import *
......@@ -35,4 +35,4 @@ sim = similarity(X, q, "cos")
print("Query vector:\n {0}\n".format(q))
print("Similarity results:\n {0}".format(sim))
print("Ran Exercise 3.1.5")
print("Ran Exercise 1.6.5")
# exercise 3.2.1
# exercise 2.1.1
import numpy as np
x = np.array([-0.68, -2.11, 2.39, 0.26, 1.46, 1.33, 1.03, -0.41, -0.33, 0.47])
......@@ -16,4 +16,4 @@ print("Standard Deviation:", std_x)
print("Median:", median_x)
print("Range:", range_x)
print("Ran Exercise 3.2.1")
print("Ran Exercise 2.1.1")
......@@ -74,4 +74,4 @@ for ms in range(5):
plt.show()
print('Ran Exercise 3.3.1')
print('Ran Exercise 2.2.1')
......@@ -39,4 +39,4 @@ print(
% (similarity(x, y, "cor") - similarity(b + x, y, "cor"))[0, 0]
)
print("Ran Exercise 3.2.2")
print("Ran Exercise 2.2.2")
# exercise 4.2.1
# exercise 2.3.1
import importlib_resources
import numpy as np
......@@ -30,4 +30,4 @@ N = len(y)
M = len(attributeNames)
C = len(classNames)
print("Ran Exercise 4.2.1")
print("Ran Exercise 2.3.1")
# Exercise 4.2.2
# Exercise 2.3.2
import numpy as np
# requires data from exercise 4.2.1
# (requires data from exercise 2.3.1 so will run that script first)
from ex2_3_1 import *
from matplotlib.pyplot import figure, hist, show, subplot, xlabel, ylim
......@@ -17,4 +15,4 @@ for i in range(M):
show()
print("Ran Exercise 4.2.2")
print("Ran Exercise 2.3.2")
# Exercise 4.2.3
# requires data from exercise 4.2.1
# Exercise 2.3.3
# (requires data from exercise 2.3.1)
from ex2_3_1 import *
from matplotlib.pyplot import boxplot, show, title, xticks, ylabel
......@@ -10,4 +9,4 @@ ylabel("cm")
title("Fisher's Iris data set - boxplot")
show()
print("Ran Exercise 4.2.3")
print("Ran Exercise 2.3.3")
# Exercise 4.2.4
# Exercise 2.3.4
# requires data from exercise 4.1.1
from ex2_3_1 import *
from matplotlib.pyplot import boxplot, figure, show, subplot, title, xticks, ylim
......@@ -21,4 +21,4 @@ for c in range(C):
show()
print("Ran Exercise 4.2.4")
print("Ran Exercise 2.3.4")
# Exercise 4.2.5
# requires data from exercise 4.2.1
# Exercise 2.3.5
# (requires data from exercise 2.3.1)
from ex2_3_1 import *
from matplotlib.pyplot import (
figure,
......@@ -29,10 +28,9 @@ for m1 in range(M):
ylabel(attributeNames[m1])
else:
yticks([])
# ylim(0,X.max()*1.1)
# xlim(0,X.max()*1.1)
legend(classNames)
show()
print("Ran Exercise 4.2.5")
print("Ran Exercise 2.3.5")
# Exercise 4.2.6
# Exercise 2.3.6
# requires data from exercise 4.1.1
# requires data from exercise 2.3.1
from ex2_3_1 import *
from matplotlib.pyplot import figure, show
from mpl_toolkits.mplot3d import Axes3D
......@@ -24,4 +24,4 @@ ax.set_zlabel(attributeNames[ind[2]])
show()
print("Ran Exercise 4.2.6")
print("Ran Exercise 2.3.6")
# Exercise 4.2.7
# Exercise 2.3.7
# requires data from exercise 4.2.1
# requires data from exercise 2.3.7
from ex2_3_1 import *
from matplotlib.pyplot import (
cm,
......@@ -27,4 +27,4 @@ colorbar()
show()
print("Ran Exercise 4.2.7")
print("Ran Exercise 2.3.7")
# exercise 4.3.1
# exercise 2.4.1
import importlib_resources
import numpy as np
......@@ -116,4 +116,4 @@ for i in range(M):
show()
print("Ran Exercise 4.3.1")
print("Ran Exercise 2.4.1")
# exercise 4.3.2
# exercise 2.4.2
import importlib_resources
import numpy as np
......@@ -69,4 +69,4 @@ for m1 in range(NumAtr):
legend(classNames)
show()
print("Ran Exercise 4.3.2")
print("Ran Exercise 2.4.2")
# exercise 2.1.1
# exercise 3.1.1
import importlib_resources
import numpy as np
import xlrd
......@@ -29,4 +29,4 @@ N = len(y)
M = len(attributeNames)
C = len(classNames)
print("Ran Exercise 2.1.1")
print("Ran Exercise 3.1.1")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment