Created
November 12, 2018 10:00
-
-
Save debonx/1b6500bc09964deedbcdec882e03f6b1 to your computer and use it in GitHub Desktop.
Basic Example to work with Scikit-Learn for calculating Linear Regressions. More at https://scikit-learn.org/
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
#Import LinearRegression methods from Scikit-Learn | |
from sklearn.linear_model import LinearRegression | |
import matplotlib.pyplot as plt | |
import numpy as np | |
#Data of Soup sales with their temperature | |
temperature = np.array(range(60, 100, 2)) | |
temperature = temperature.reshape(-1, 1) | |
sales = [65, 58, 46, 45, 44, 42, 40, 40, 36, 38, 38, 28, 30, 22, 27, 25, 25, 20, 15, 5] | |
plt.plot(temperature, sales, 'o') | |
plt.show() | |
#Call the class adn fitting with data | |
line_fitter = LinearRegression() | |
line_fitter.fit(temperature, sales) | |
#Predict sales on temperature | |
sales_predict = line_fitter.predict(temperature) | |
#Show Linear Regression | |
plt.plot(temperature, sales_predict, 'o') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment