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

Add a sample notebook. Refactor regression out.

parent 0feb1cbc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
build/
dist/
xlap.egg-info/
.ipynb_checkpoints/
 No newline at end of file

notebook.ipynb

0 → 100644
+117 −0

File added.

Preview size limit exceeded, changes collapsed.

+0 −11
Original line number Diff line number Diff line
import math
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model

plt.rcParams["figure.figsize"] = (16, 9)
plt.rcParams.update({'figure.autolayout': True})
@@ -9,16 +8,6 @@ plt.rcParams.update({'figure.autolayout': True})

# 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):
+21 −0
Original line number Diff line number Diff line
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()