Learn Before
Code

Python: Simple Linear Regression

#imports import numpy as np from sklearn.linear_model import LinearRegression #make up data array_x = np.array([5, 10, 15, 20, 25]).reshape((-1, 1)) #calling reshape makes sure that the array is 2D array_y = np.array([5, 3, 15, 23, 6]) #create a model model_xy = LinearRegression() #using model mode.fit(array_x, array_y) #getting results rsq_val = model_xy(array_x, array_y) intercept = model_xy.intercept_ slope = model_xy.coef_ #predicting a response y_pred = model_xy.predict(x)

0

4

Updated 2020-04-07

Tags

Data Science