# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# %matplotlib inline

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

plt.style.use("ggplot")
plt.rcParams["font.size"] = 14
plt.rcParams["figure.figsize"] = 8, 6
# -

dat = pd.read_csv("income_expenses.csv")
x = dat["income"]
y = dat["expenses"]
plt.plot(x, y, "o")
plt.xlim(0, 1200)
plt.ylim(0, 1200)
plt.xlabel("income [jpy]")
plt.ylabel("expenses [jpy]")
plt.show()

corr = np.corrcoef(x, y)
print(corr)

from sklearn import linear_model
model = linear_model.LinearRegression()
model.fit(x[:, np.newaxis], y)

print(model.coef_, model.intercept_)

print(model.predict([600]))

xx = np.array([300,400,500])[:, np.newaxis]
model.predict(xx)

xx= np.arange(100, 1200, 100)
yy = model.predict(xx[:, np.newaxis])
plt.plot(xx, yy, label="predicted")
plt.plot(x, y, "o", label="observed")
plt.xlabel("income [jpy]")
plt.ylabel("expenses [jpy]")
plt.xlim(0, 1200)
plt.ylim(0, 1200)
plt.legend()

print(model.score(x[:, np.newaxis], y))

data = pd.read_csv("blood_fat.csv")
data.head(5)

X = data.copy()
y = X.pop("blood fat")
model = linear_model.LinearRegression().fit(X, y)

y_pred = model.predict(X)
plt.plot(np.linspace(min(y), max(y), 100), np.linspace(min(y), max(y), 100))
plt.plot(y, y_pred, "o")
plt.xlabel("y")
plt.ylabel("y_pred")

print(model.score(X, y))

StarcoderdataJupyterScriptsDedupFiltered