Last active
November 7, 2017 19:36
-
-
Save dkreider/1b883220cda7f82b77ff46fec175120f to your computer and use it in GitHub Desktop.
Very basic single linear regression example in Python
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
# Very basic single linear regression example in Python. Daniel Kreider Oct. 28 2017 | |
# | |
# | |
# X(input) | |
# 9 | | |
# 8 | * | |
# 7 | * | |
# 6 | * | |
# 5 | * | |
# 4 | * | |
# 3 | * | |
# 2 | * | |
# 1 |_ _ _ _ _ _ _ _ _ | |
# 1 2 3 4 5 6 7 8 9 Y(output) | |
import pandas as pd | |
from sklearn.linear_model import LinearRegression | |
from matplotlib import pyplot as plt | |
XData = [1,2,3,4,5,6,7,8,9]; # Input | |
yData = [2,3,4,5,6,7,8,9,10]; # Outcome | |
X = pd.DataFrame(XData); | |
y = pd.DataFrame(yData); | |
lm = LinearRegression(); | |
model = lm.fit(X, y); | |
xTest = input("Please enter a number: "); | |
prediction = model.predict(int(xTest)); | |
print("Based on your input, the trained model returned: ", prediction[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment