Skip to content

Instantly share code, notes, and snippets.

@sanikamal
Created November 12, 2020 12:11
Show Gist options
  • Save sanikamal/5367245a045831e4e1442d73bcc4ad18 to your computer and use it in GitHub Desktop.
Save sanikamal/5367245a045831e4e1442d73bcc4ad18 to your computer and use it in GitHub Desktop.
Simple Linear Regression:Template Code
#Import Library
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
#Load Train and Test datasets
#Identify feature and response variable(s)
x_train=input_variables_values_training_datasets
y_train=target_variables_values_training_datasets
x_test=input_variables_values_test_datasets
# Create linear regression object
linear = LinearRegression()
# Train the model using the training sets and check score
linear.fit(x_train, y_train)
linear.score(x_train, y_train)
#Equation coefficient and Intercept
print('Coefficient: \n', linear.coef_)
print('Intercept: \n', linear.intercept_)
#Make Prediction
predicted= linear.predict(x_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment