Skip to content

Instantly share code, notes, and snippets.

@purnasai
Last active February 24, 2019 19:37
Show Gist options
  • Save purnasai/148b2157f9e7917f3c203470c5d1d2c4 to your computer and use it in GitHub Desktop.
Save purnasai/148b2157f9e7917f3c203470c5d1d2c4 to your computer and use it in GitHub Desktop.
# importing libraries
#for versions checkout requirements.txt
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#importing and reading data sets
data = pd.read_csv("bmi_and_life.csv")
#look at top 5 rows in data set
data.head()
#delete/drop 'Country' variable.
data = data.drop(['Country'], axis = 1)
#reading into variables
X = data.iloc[:, :-1].values
Y = data.iloc[:, 1].values
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,Y, test_size = 20, random_state = 0)
#import linear regression
from sklearn.linear_model import LinearRegression
lr = LinearRegression()
#fitting the model
lr.fit(X_train,y_train)
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)
# Predicting the Test set results
y_pred = lr.predict(X_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment