Spaces:
Runtime error
Runtime error
Delete regularization-ridge.py
Browse files- regularization-ridge.py +0 -42
regularization-ridge.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""Gradio-regression.ipynb
|
3 |
-
|
4 |
-
Automatically generated by Colaboratory.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/1qmfhcPafAIfczazACroyAYyRohdQbklK
|
8 |
-
"""
|
9 |
-
import numpy as np
|
10 |
-
import matplotlib.pyplot as plt
|
11 |
-
import seaborn as sns
|
12 |
-
import gradio as gr
|
13 |
-
from sklearn.linear_model import Ridge, LinearRegression
|
14 |
-
from sklearn.model_selection import train_test_split
|
15 |
-
np.random.seed(2)
|
16 |
-
|
17 |
-
X = 2 * np.random.rand(100, 1)
|
18 |
-
y = 4 + 3 * X
|
19 |
-
|
20 |
-
X_train, X_test, y_train, y_test = train_test_split(
|
21 |
-
X, y, test_size=0.1, random_state=42)
|
22 |
-
|
23 |
-
def build_model(alpha):
|
24 |
-
r_reg = Ridge(alpha=alpha)
|
25 |
-
r_reg.fit(X_train, y_train)
|
26 |
-
return r_reg
|
27 |
-
|
28 |
-
def predict(alpha):
|
29 |
-
ridge_reg = build_model(alpha)
|
30 |
-
preds = ridge_reg.predict(X_test)
|
31 |
-
fig = plt.figure()
|
32 |
-
plt.plot(X_test, y_test, "r-")
|
33 |
-
plt.plot(X_test, preds, "b--")
|
34 |
-
plt.title("Effect of regularization parameter on Ridge regression")
|
35 |
-
plt.ylabel("Y")
|
36 |
-
plt.xlabel("X")
|
37 |
-
return plt
|
38 |
-
|
39 |
-
inputs = gr.Number()
|
40 |
-
outputs = gr.Plot()
|
41 |
-
gr.Interface(fn = predict, inputs = inputs, outputs = outputs).launch()
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|