Skip to content

Instantly share code, notes, and snippets.

@grohith327
Created May 27, 2018 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grohith327/34d8e17c27965ba899baa6dc0355a099 to your computer and use it in GitHub Desktop.
Save grohith327/34d8e17c27965ba899baa6dc0355a099 to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
df_train = pd.read_csv('/Users/rohith/Documents/Datasets/Linear_Regression/train.csv')
df_test = pd.read_csv('/Users/rohith/Documents/Datasets/Linear_Regression/test.csv')
x_train = df_train['x']
y_train = df_train['y']
x_test = df_test['x']
y_test = df_test['y']
x_train = np.array(x_train)
y_train = np.array(y_train)
x_test = np.array(x_test)
y_test = np.array(y_test)
x_train = x_train.reshape(-1,1)
x_test = x_test.reshape(-1,1)
Copy link

ghost commented Sep 2, 2020

Hello Rohith,

Thank you for such a wonderful content. I have a question here, is there any reason why you have reshaped the array to 1 column? Because i think it will work without reshaping the array too.

@grohith327
Copy link
Author

Hello Raj, Thank you for your kind words. Later in the example we manually calculate the gradients and update the weights which requires some matmul, therefore, to ensure it works smoothly we reshape the matrix. If you are going to be using the sklearn package to perform linear regression I guess the reshaping is only an addition. Thank you.

@khalAMo
Copy link

khalAMo commented May 24, 2022

Thank you Rohith,
How can I get the CSV to test the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment