-
-
Save karanjagota/db0531d28bf7596e4f828d9078f7db4a to your computer and use it in GitHub Desktop.
gist for medium blogs ..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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