Posts

Showing posts with the label Linear Regression

Day 5 - Linear Regression Numpy Code and Python

Python  In the course today we learned about the following concepts: Lists  Dictionaries Tuples Sets Booleans Dealing with Files in Python Iterating in a file Linear Regression Numpy Code The code was completed and it was: import math beta = beta_zero cost_diff = 100 rmse =-1 for i in range(10000):     old_rmse = rmse     y_hatnew = x_data.dot(beta)              y_diff =y_true.reshape(len(x_inputs),1) - y_hatnew              rmse = math.sqrt(y_diff.T.dot(y_diff)/x_data.shape[0])     print(i,":",rmse)              if abs(rmse-old_rmse) < 0.000000000001:         break          derivative = 2*y_diff.T.dot(x_data)/x_data.shape[0]     beta = beta+step*derivative.T print(beta)  The next task given to us was to impl...

Day 4 - Linear Regression Numpy code and Python course

Linear Regression Numpy code   We finished coding generating data for the numpy version of Linear regression. We didn't use data from an excel sheet or a Kaggle dataset and hence we had to create our own data. For this, we created random integer data for our X and betas. Then we created a noise, as real data always has noise, using this we created Y data. the code for the same was as follows: import numpy as np samplesize=1000 num_attrs= 3 step = 0.1 x_inputs = np.random.rand(samplesize,num_attrs-1) x0 = np.ones((samplesize,1)) x_data = np.concatenate((x0, x_inputs), axis=1) noise = np.random.randn(len(x_inputs),1)  betas = np.random.rand(num_attrs,1) y_true = x_data.dot(betas) + noise  #understand this y_true.reshape(1000,1) Python course  We started an Udemy course on Python. The concepts we covered today were: Pros and Cons of Dynamic Typing String Indexing and Slicing Various String Methods String Interpolation:  ...

Day 2 - Introduction to Linear Regression

Introduction to Linear Regression Simple linear regression is useful for finding a relationship between two continuous variables. One is a predictor or independent variable and other is a response or dependent variable. It looks for a statistical relationship but not a deterministic relationship. The relationship between the two variables is said to be deterministic if one variable can be accurately expressed by the other. For example, using temperature in degree Celsius it is possible to accurately predict Fahrenheit. Statistical relationship is not accurate in determining the relationship between two variables. For example, the relationship between height and weight. With simple linear regression we want to model our data as follows: y = B0 + B1 * x This is a line where y is the output variable we want to predict, x is the input variable we know and B0 and B1 are coefficients we need to estimate. It also required us to understand the concept of gradient descent.  G...