Skip to content

Instantly share code, notes, and snippets.

@karanjagota karanjagota/sklearn_ex.py Secret
Created Jul 5, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.