Last active
February 7, 2018 12:02
-
-
Save pmendonca/b8f21915b782070ac47844cc8afc95ee to your computer and use it in GitHub Desktop.
Very basic sckit linear regression example
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
from sklearn import datasets | |
from sklearn.model_selection import cross_val_predict | |
from sklearn import linear_model | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from sklearn.metrics import r2_score | |
import pandas as pd | |
# Scrubbing | |
# lista com os meses do ano Jan-Dez | |
_yData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | |
# lista com o faturamento em Milhões | |
_xData = [10, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 11, 11.1] | |
# Training Data (70%), do mês 4 em diante. | |
_yTrain = _yData[3:] | |
# Test Data (30%), do mês 1 ao 3 | |
_yTest = _yData[:3] | |
dfTrain = pd.DataFrame({'x': _xData[3:] }) | |
dfTest = pd.DataFrame({'x': _xData[:3] }) | |
lr = linear_model.LinearRegression() | |
# Treinamento Supervisionado | |
lr.fit(dfTrain[['x']], _yTrain) | |
# Testes | |
results = lr.predict(dfTest[['x']]) | |
# Coeficiente de Determinação (R^2) | |
print('%.2f' % r2_score(_yTest, results)) | |
# Predição (em qual mes se alcança 11.5M em faturamento?) | |
print(lr.predict(pd.DataFrame({'x': [11.5] }))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment