Skip to content

Instantly share code, notes, and snippets.

@karanjagota
Created July 5, 2019 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karanjagota/db0531d28bf7596e4f828d9078f7db4a to your computer and use it in GitHub Desktop.
Save karanjagota/db0531d28bf7596e4f828d9078f7db4a to your computer and use it in GitHub Desktop.
gist for medium blogs ..
# importing necessary modules ...
from sklearn.linear_model import LinearRegression
# creating a copy of our existing dataframe ...
df_copy = df
# one hot encoding .. pre-requisite for LinearRegression ...
df_copy['origin'] = pd.get_dummies(df_copy['origin'])
# creating Training set and Test set from what we have learn't from above ...
x_train = df_copy.iloc[0:300,1:8]
x_test = df_copy.iloc[300:393,1:8]
y_true = df_copy.iloc[0:300,0:1]
y_test = df_copy.iloc[300:393,0:1]
# initialising the Linear Regression model ..
linear_regression_model = LinearRegression()
# fitting the model onto our features / X_train ...
linear_regression_model.fit(x_train,y_true)
# predicting the result on test_set ...
y_pred = linear_regression_model.predict(x_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment