Commit 034268b7 authored by Andreas Schmidt's avatar Andreas Schmidt

Add a sample notebook. Refactor regression out.

parent 0feb1cbc
build/ build/
dist/ dist/
xlap.egg-info/ xlap.egg-info/
.ipynb_checkpoints/
\ No newline at end of file
This diff is collapsed.
import math import math
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from sklearn import linear_model
plt.rcParams["figure.figsize"] = (16, 9) plt.rcParams["figure.figsize"] = (16, 9)
plt.rcParams.update({'figure.autolayout': True}) plt.rcParams.update({'figure.autolayout': True})
...@@ -9,16 +8,6 @@ plt.rcParams.update({'figure.autolayout': True}) ...@@ -9,16 +8,6 @@ plt.rcParams.update({'figure.autolayout': True})
# TODO: Refactor. # TODO: Refactor.
def regress(df, column):
x = df.index.values.reshape(-1, 1)
y = df[column].values
model = linear_model.LinearRegression()
model.fit(x, y)
print("R-Score:", model.score(x, y))
plt.scatter(x, y)
plt.grid()
plt.plot(x, model.predict(x), color="red", linewidth=3)
def trace(df, title, export=False): def trace(df, title, export=False):
......
from sklearn import linear_model
import matplotlib.pyplot as plt
def linear(data_frame, column):
"""
Execute a simple linear regression on the given column for the passed data_frame.
:param data_frame:
:param column:
:return:
"""
x = data_frame.index.values.reshape(-1, 1)
y = data_frame[column].values
model = linear_model.LinearRegression()
model.fit(x, y)
print("R-Score:", model.score(x, y))
plt.scatter(x, y)
plt.grid()
plt.plot(x, model.predict(x), color="red", linewidth=3)
plt.show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment