Skip to content
Snippets Groups Projects
Commit 74eb8c60 authored by Dellandrea Emmanuel's avatar Dellandrea Emmanuel
Browse files

Update

parent ffdc84e5
No related branches found
No related tags found
No related merge requests found
.DS_Store
File added
File added
File added
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
7.4764,4.3483
8.5781,12
6.4862,6.5987
5.0546,3.8166
5.7107,3.2522
14.164,15.505
5.734,3.1551
8.4084,7.2258
5.6407,0.71618
5.3794,3.5129
6.3654,5.3048
5.1301,0.56077
6.4296,3.6518
7.0708,5.3893
6.1891,3.1386
20.27,21.767
5.4901,4.263
6.3261,5.1875
5.5649,3.0825
18.945,22.638
12.828,13.501
10.957,7.0467
13.176,14.692
22.203,24.147
5.2524,-1.22
6.5894,5.9966
9.2482,12.134
5.8918,1.8495
8.2111,6.5426
7.9334,4.5623
8.0959,4.1164
5.6063,3.3928
12.836,10.117
6.3534,5.4974
5.4069,0.55657
6.8825,3.9115
11.708,5.3854
5.7737,2.4406
7.8247,6.7318
7.0931,1.0463
5.0702,5.1337
5.8014,1.844
11.7,8.0043
5.5416,1.0179
7.5402,6.7504
5.3077,1.8396
7.4239,4.2885
7.6031,4.9981
6.3328,1.4233
6.3589,-1.4211
6.2742,2.4756
5.6397,4.6042
9.3102,3.9624
9.4536,5.4141
8.8254,5.1694
5.1793,-0.74279
21.279,17.929
14.908,12.054
18.959,17.054
7.2182,4.8852
8.2951,5.7442
10.236,7.7754
5.4994,1.0173
20.341,20.992
10.136,6.6799
7.3345,4.0259
6.0062,1.2784
7.2259,3.3411
5.0269,-2.6807
6.5479,0.29678
7.5386,3.8845
5.0365,5.7014
10.274,6.7526
5.1077,2.0576
5.7292,0.47953
5.1884,0.20421
6.3557,0.67861
9.7687,7.5435
6.5159,5.3436
8.5172,4.2415
9.1802,6.7981
6.002,0.92695
5.5204,0.152
5.0594,2.8214
5.7077,1.8451
7.6366,4.2959
5.8707,7.2029
5.3054,1.9869
8.2934,0.14454
13.394,9.0551
5.4369,0.61705
2104,3,399900
1600,3,329900
2400,3,369000
1416,2,232000
3000,4,539900
1985,4,299900
1534,3,314900
1427,3,198999
1380,3,212000
1494,3,242500
1940,4,239999
2000,3,347000
1890,3,329999
4478,5,699900
1268,3,259900
2300,4,449900
1320,2,299900
1236,3,199900
2609,4,499998
3031,4,599000
1767,3,252900
1888,2,255000
1604,3,242900
1962,4,259900
3890,3,573900
1100,3,249900
1458,3,464500
2526,3,469000
2200,3,475000
2637,3,299900
1839,2,349900
1000,1,169900
2040,4,314900
3137,3,579900
1811,4,285900
1437,3,249900
1239,3,229900
2132,4,345000
4215,4,549000
2162,4,287000
1664,2,368500
2238,3,329900
2567,4,314000
1200,3,299000
852,2,179900
1852,4,299900
1203,3,239500
import matplotlib.pyplot as plt
import numpy as np
def read_data(file_name, delimiter=','):
""" Read the data file and returns the corresponding matrices
Parameters
----------
file_name : file name containg data
delimiter : character separating columns in the file ("," by default)
Returns
-------
X : data matrix of size [N, nb_var]
Y : matrix containg values of the target variable of size [N, 1]
with N : number of elements and nb_var : number of predictor variables
"""
data = np.loadtxt(file_name, delimiter=delimiter)
#######################
##### To complete #####
#######################
return X, Y, N, nb_var
def normalization(X):
""" Normalize the provided matrix (substracts mean and divides by standard deviation)
Parameters
----------
X : data matrix of size [N, nb_var]
with N : number of elements and nb_var : number of predictor variables
Returns
-------
X_norm : normalized data matrix of size [N, nb_var]
mu : means of the variables of sizede dimension [1,nb_var]
sigma : standar deviations of the variables of size [1,nb_var]
"""
#######################
##### To complete #####
#######################
return X_norm, mu, sigma
def compute_loss(X, Y, theta):
""" Compute the loss function value (mean square error)
Parameters
----------
X : data matrix of size [N, nb_var+1]
Y : matrix containg values of the target variable of size [N, 1]
theta : matrix containing the theta parameters of the linear model of size [1, nb_var+1]
with N : number of elements and nb_var : number of predictor variables
Returns
-------
loss : loss function value (mean square error)
"""
#######################
##### To complete #####
#######################
return loss
def gradient_descent(X, Y, theta, alpha, nb_iters):
""" Training to compute the linear regression parameters by gradient descent
Parameters
----------
X : data matrix of size [N, nb_var+1]
Y : matrix containg values of the target variable of size [N, 1]
theta : matrix containing the theta parameters of the linear model of size [1, nb_var+1]
alpha : learning rate
nb_iters : number of iterations
with N : number of elements and nb_var : number of predictor variables
Returns
-------
theta : matrix containing the theta parameters learnt by gradient descent of size [1, nb_var+1]
J_history : list containg the loss function values for each iteration of length nb_iters
"""
# Init of useful variables
N = X.shape[0]
J_history = np.zeros(nb_iters)
for i in range(0, nb_iters):
#######################
##### To complete #####
#######################
return theta, J_history
def display(X, Y, theta):
""" Display in 2 dimensions of data points and of the linear regression curve defined by theta parameters
Parameters
----------
X : data matrix of size [N, nb_var+1]
Y : matrix containg values of the target variable of size [N, 1]
theta : matrix containing the theta parameters of the linear model of size [1, nb_var+1]
with N : number of elements and nb_var : number of predictor variables
Returns
-------
None
"""
#######################
##### To complete #####
#######################
plt.show()
if __name__ == "__main__":
# ===================== Part 1: Data loading and normalization =====================
print("Data loading ...")
X, Y, N, nb_var = read_data("food_truck.txt")
# X, Y, N, nb_var = read_data("houses.txt")
# Print of the ten first examples of the dataset
print("Print of the ten first examples of the dataset : ")
for i in range(0, 10):
print(f"x = {X[i,:]}, y = {Y[i]}")
# Normalization of variables
print("Normalization of variables ...")
X, mu, sigma = normalization(X)
# Add one column of 1 values to X (for theta 0)
X = np.hstack((np.ones((N,1)), X))
# ===================== Part 2: Gradient descent =====================
print("Training by gradient descent ...")
# Choice of the learning rate and number of iterations
alpha = 0.01
nb_iters = 1500
# Initialization of theta and call to the gradient descent function
theta = np.zeros((1,nb_var+1))
theta, J_history = gradient_descent(X, Y, theta, alpha, nb_iters)
# Display of the loss function values obtained during gradient descent training
plt.figure()
plt.title("Loss function values obtained during gradient descent training")
plt.plot(np.arange(J_history.size), J_history)
plt.xlabel("Nomber of iterations")
plt.ylabel("Loss function J")
# Print of theta values
print(f"Theta computed by gradient descent : {theta}")
# In case of only one predictor variable, display the linear regression curve
if nb_var == 1 :
display(X,Y,theta)
plt.show()
print("Linear Regression completed.")
import matplotlib.pyplot as plt
import numpy as np
def read_data(file_name, delimiter=','):
""" Read the data file and returns the corresponding matrices
Parameters
----------
file_name : file name containg data
delimiter : character separating columns in the file ("," by default)
Returns
-------
X : data matrix of size [N, nb_var]
Y : matrix containg values of the target variable of size [N, 1]
with N : number of elements and nb_var : number of predictor variables
"""
data = np.loadtxt(file_name, delimiter=delimiter)
#######################
##### To complete #####
#######################
return X, Y, N, nb_var
def normalization(X):
""" Normalize the provided matrix (substracts mean and divides by standard deviation)
Parameters
----------
X : data matrix of size [N, nb_var]
with N : number of elements and nb_var : number of predictor variables
Returns
-------
X_norm : normalized data matrix of size [N, nb_var]
mu : means of the variables of sizede dimension [1,nb_var]
sigma : standar deviations of the variables of size [1,nb_var]
"""
#######################
##### To complete #####
#######################
return X_norm, mu, sigma
def sigmoid(z):
""" Compute the value of the sigmoid function applied to z
Parameters
----------
z : can be a scalar value or a matrix
Returns
-------
s : sigmoid value of z. Same size as z
"""
#######################
##### To complete #####
#######################
return s
def compute_loss(X, Y, theta):
""" Compute the loss function value (log likelihood)
Parameters
----------
X : data matrix of size [N, nb_var+1]
Y : matrix containg values of the target variable of size [N, 1]
theta : matrix containing the theta parameters of the linear model of size [1, nb_var+1]
with N : number of elements and nb_var : number of predictor variables
Returns
-------
loss : loss function value (log likelihood)
"""
#######################
##### To complete #####
#######################
return loss
def gradient_descent(X, Y, theta, alpha, nb_iters):
""" Training to compute the logistic regression parameters by gradient descent
Parameters
----------
X : data matrix of size [N, nb_var+1]
Y : matrix containg values of the target variable of size [N, 1]
theta : matrix containing the theta parameters of the logistic model of size [1, nb_var+1]
alpha : learning rate
nb_iters : number of iterations
with N : number of elements and nb_var : number of predictor variables
Returns
-------
theta : matrix containing the theta parameters learnt by gradient descent of size [1, nb_var+1]
J_history : list containg the loss function values for each iteration of length nb_iters
"""
# Init of useful variables
N = X.shape[0]
J_history = np.zeros(nb_iters)
for i in range(0, nb_iters):
#######################
##### To complete #####
#######################
return theta, J_history
def prediction(X,theta):
""" Predict the class of each element in X
Parameters
----------
X : data matrix of size [N, nb_var+1]
Y : matrix containg values of the target variable of size [N, 1]
theta : matrix containing the theta parameters of the logistic model of size [1, nb_var+1]
with N : number of elements and nb_var : number of predictor variables
Returns
-------
p : matrix of size [N,1] providing the class of each element in X (either 0 or 1)
"""
#######################
##### To complete #####
#######################
return p
def classification_rate(Ypred,Y):
""" Compute the classification rate (proportion of correctly classified elements)
Parameters
----------
Ypred : matrix containing the predicted values of the class of size [N, 1]
Y : matrix containing the values of the target variable of size [N, 1]
with N : number of elements
Returns
-------
r : classification rate
"""
#######################
##### To complete #####
#######################
return r
def display(X, Y):
""" Display of data in 2 dimensions (2 dimensions of X) and class representation (provided by Y) by a color
Parameters
----------
X : data matrix of size [N, nb_var+1]
Y : matrix containg values of the target variable of size [N, 1]
with N : number of elements and nb_var : number of predictor variables
Returns
-------
None
"""
#######################
##### To complete #####
#######################
if __name__ == "__main__":
# ===================== Part 1: Data loading and normalization =====================
print("Data loading ...")
X, Y, N, nb_var = read_data("notes.txt")
# Print of the ten first examples of the dataset
print("Print of the ten first examples of the dataset : ")
for i in range(0, 10):
print(f"x = {X[i,:]}, y = {Y[i]}")
# Normalization of variables
print("Normalization of variables ...")
X, mu, sigma = normalization(X)
# Add one column of 1 values to X (for theta 0)
X = np.hstack((np.ones((N,1)), X))
# Display in 2D of data points and actual class representation by a color
if nb_var == 2 :
plt.figure(0)
plt.title("Coordinates of data points in 2D - Reality")
display(X,Y)
# ===================== Part 2: Gradient descent =====================
print("Training by gradient descent ...")
# Choice of the learning rate and number of iterations
alpha = 0.01
nb_iters = 10000
# Initialization of theta and call to the gradient descent function
theta = np.zeros((1,nb_var+1))
theta, J_history = gradient_descent(X, Y, theta, alpha, nb_iters)
# Display of the loss function values obtained during gradient descent training
plt.figure()
plt.title("Loss function values obtained during gradient descent training")
plt.plot(np.arange(J_history.size), J_history)
plt.xlabel("Nomber of iterations")
plt.ylabel("Loss function J")
# Print of theta values
print(f"Theta computed by gradient descent : {theta}")
# Evaluation of the model
Ypred = prediction(X,theta)
print("Classification rate : ", classification_rate(Ypred,Y))
# Display in 2D of data points and predicted class representation by a color
if nb_var == 2 :
plt.figure(0)
plt.title("Coordinates of data points in 2D - Prediction")
display(X,Y)
plt.show()
print("Logistic Regression completed.")
34.62365962451697,78.0246928153624,0
30.28671076822607,43.89499752400101,0
35.84740876993872,72.90219802708364,0
60.18259938620976,86.30855209546826,1
79.0327360507101,75.3443764369103,1
45.08327747668339,56.3163717815305,0
61.10666453684766,96.51142588489624,1
75.02474556738889,46.55401354116538,1
76.09878670226257,87.42056971926803,1
84.43281996120035,43.53339331072109,1
95.86155507093572,38.22527805795094,0
75.01365838958247,30.60326323428011,0
82.30705337399482,76.48196330235604,1
69.36458875970939,97.71869196188608,1
39.53833914367223,76.03681085115882,0
53.9710521485623,89.20735013750205,1
69.07014406283025,52.74046973016765,1
67.94685547711617,46.67857410673128,0
70.66150955499435,92.92713789364831,1
76.97878372747498,47.57596364975532,1
67.37202754570876,42.83843832029179,0
89.67677575072079,65.79936592745237,1
50.534788289883,48.85581152764205,0
34.21206097786789,44.20952859866288,0
77.9240914545704,68.9723599933059,1
62.27101367004632,69.95445795447587,1
80.1901807509566,44.82162893218353,1
93.114388797442,38.80067033713209,0
61.83020602312595,50.25610789244621,0
38.78580379679423,64.99568095539578,0
61.379289447425,72.80788731317097,1
85.40451939411645,57.05198397627122,1
52.10797973193984,63.12762376881715,0
52.04540476831827,69.43286012045222,1
40.23689373545111,71.16774802184875,0
54.63510555424817,52.21388588061123,0
33.91550010906887,98.86943574220611,0
64.17698887494485,80.90806058670817,1
74.78925295941542,41.57341522824434,0
34.1836400264419,75.2377203360134,0
83.90239366249155,56.30804621605327,1
51.54772026906181,46.85629026349976,0
94.44336776917852,65.56892160559052,1
82.36875375713919,40.61825515970618,0
51.04775177128865,45.82270145776001,0
62.22267576120188,52.06099194836679,0
77.19303492601364,70.45820000180959,1
97.77159928000232,86.7278223300282,1
62.07306379667647,96.76882412413983,1
91.56497449807442,88.69629254546599,1
79.94481794066932,74.16311935043758,1
99.2725269292572,60.99903099844988,1
90.54671411399852,43.39060180650027,1
34.52451385320009,60.39634245837173,0
50.2864961189907,49.80453881323059,0
49.58667721632031,59.80895099453265,0
97.64563396007767,68.86157272420604,1
32.57720016809309,95.59854761387875,0
74.24869136721598,69.82457122657193,1
71.79646205863379,78.45356224515052,1
75.3956114656803,85.75993667331619,1
35.28611281526193,47.02051394723416,0
56.25381749711624,39.26147251058019,0
30.05882244669796,49.59297386723685,0
44.66826172480893,66.45008614558913,0
66.56089447242954,41.09209807936973,0
40.45755098375164,97.53518548909936,1
49.07256321908844,51.88321182073966,0
80.27957401466998,92.11606081344084,1
66.74671856944039,60.99139402740988,1
32.72283304060323,43.30717306430063,0
64.0393204150601,78.03168802018232,1
72.34649422579923,96.22759296761404,1
60.45788573918959,73.09499809758037,1
58.84095621726802,75.85844831279042,1
99.82785779692128,72.36925193383885,1
47.26426910848174,88.47586499559782,1
50.45815980285988,75.80985952982456,1
60.45555629271532,42.50840943572217,0
82.22666157785568,42.71987853716458,0
88.9138964166533,69.80378889835472,1
94.83450672430196,45.69430680250754,1
67.31925746917527,66.58935317747915,1
57.23870631569862,59.51428198012956,1
80.36675600171273,90.96014789746954,1
68.46852178591112,85.59430710452014,1
42.0754545384731,78.84478600148043,0
75.47770200533905,90.42453899753964,1
78.63542434898018,96.64742716885644,1
52.34800398794107,60.76950525602592,0
94.09433112516793,77.15910509073893,1
90.44855097096364,87.50879176484702,1
55.48216114069585,35.57070347228866,0
74.49269241843041,84.84513684930135,1
89.84580670720979,45.35828361091658,1
83.48916274498238,48.38028579728175,1
42.2617008099817,87.10385094025457,1
99.31500880510394,68.77540947206617,1
55.34001756003703,64.9319380069486,1
74.77589300092767,89.52981289513276,1
# Deep_Learning
# Deep Learning Course
Bsc Data Science for Responsible Business
Centrale Lyon
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.ec-lyon.fr/edelland/deep_learning.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.ec-lyon.fr/edelland/deep_learning/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
Emmanuel Dellandréa - emmanuel.dellandrea@ec-lyon.fr
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment