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
theilsen = TheilSenRegressor(random_state=42).fit(X, y) | |
fit_df["theilsen_regression"] = theilsen.predict(plotline_X) | |
coef_list.append(["theilsen_regression", theilsen.coef_[0]]) |
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
plt.scatter(X[inlier_mask], y[inlier_mask], color="blue", label="Inliers") | |
plt.scatter(X[outlier_mask], y[outlier_mask], color="red", label="Outliers") | |
plt.title("RANSAC - outliers vs inliers"); |
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
inlier_mask = ransac.inlier_mask_ | |
outlier_mask = ~inlier_mask | |
print(f"Total outliers: {sum(outlier_mask)}") | |
print(f"Outliers we have added ourselves: {sum(outlier_mask[:N_OUTLIERS])} / {N_OUTLIERS}") |
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
ransac = RANSACRegressor(random_state=42).fit(X, y) | |
fit_df["ransac_regression"] = ransac.predict(plotline_X) | |
ransac_coef = ransac.estimator_.coef_ | |
coef_list.append(["ransac_regression", ransac.estimator_.coef_[0]]) |
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
huber = HuberRegressor().fit(X, y) | |
fit_df["huber_regression"] = huber.predict(plotline_X) | |
coef_list.append(["huber_regression", huber.coef_[0]]) |
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
fix, ax = plt.subplots() | |
fit_df.plot(ax=ax) | |
plt.scatter(X, y, c="k") | |
plt.title("Linear regression on data with outliers"); |
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
plotline_X = np.arange(X.min(), X.max()).reshape(-1, 1) | |
fit_df = pd.DataFrame( | |
index = plotline_X.flatten(), | |
data={"linear_regression": lr.predict(plotline_X)} | |
) |
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
N_SAMPLES = 500 | |
N_OUTLIERS = 25 | |
X, y, coef = datasets.make_regression( | |
n_samples=N_SAMPLES, | |
n_features=1, | |
n_informative=1, | |
noise=20, | |
coef=True, | |
random_state=42 |
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
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from sklearn import datasets | |
from sklearn.linear_model import (LinearRegression, HuberRegressor, | |
RANSACRegressor, TheilSenRegressor) |
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 shiny import App, render, ui | |
import yfinance as yf | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
app_ui = ui.page_fluid( | |
ui.h2("Stock price tracker"), | |
ui.layout_sidebar( | |
ui.panel_sidebar( | |
ui.input_select( |
NewerOlder