marik0 commited on
Commit
7c2d8b9
Β·
1 Parent(s): 0ab3e6b

Improve description and figure

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -5,12 +5,15 @@ import numpy as np
5
  from sklearn import datasets, linear_model
6
  from sklearn.metrics import mean_squared_error, r2_score
7
 
 
 
 
8
  FIGSIZE = (10,10)
9
 
10
- feature_names = ["age", "body-mass index (BMI)", "blood pressure",
11
- "total serum cholesterol", "low-density lipoproteins (LDL)",
12
- "high-density lipoproteins (HDL)", "total cholesterol / HDL",
13
- "log of serum triglycerides level (possibly)","blood sugar level"]
14
 
15
  def create_dataset(feature_id=2):
16
  # Load the diabetes dataset
@@ -59,15 +62,24 @@ def train_model(input_data):
59
  plt.scatter(diabetes_X_test, diabetes_y_test, color="black")
60
  plt.plot(diabetes_X_test, diabetes_y_pred, color="blue", linewidth=3)
61
 
 
 
 
62
  plt.xticks(())
63
  plt.yticks(())
64
 
65
-
66
-
67
  return fig, regr.coef_, mse, r2
68
 
69
  title = "Linear Regression Example πŸ“ˆ"
70
- description = "The example shows how linear regression attempts to draw a straight line that will best minimize the residual sum of squares between the observed responses in the dataset"
 
 
 
 
 
 
 
 
71
  with gr.Blocks() as demo:
72
  gr.Markdown(f"## {title}")
73
  gr.Markdown(description)
@@ -79,8 +91,8 @@ with gr.Blocks() as demo:
79
  with gr.Column():
80
  input_data = gr.Dropdown(choices=feature_names, label="Feature", value="body-mass index")
81
  coef = gr.Textbox(label="Coefficients")
82
- mse = gr.Textbox(label="MSE")
83
- r2 = gr.Textbox(label="R2")
84
 
85
  input_data.change(fn=train_model, inputs=[input_data], outputs=[plot, coef, mse, r2], queue=False)
86
 
 
5
  from sklearn import datasets, linear_model
6
  from sklearn.metrics import mean_squared_error, r2_score
7
 
8
+ import matplotlib
9
+ matplotlib.use('agg')
10
+
11
  FIGSIZE = (10,10)
12
 
13
+ feature_names = ["Age", "Body-Mass Index (BMI)", "Blood Pressure",
14
+ "Total serum Cholesterol", "Low-Density Lipoproteins (LDL)",
15
+ "High-Density Lipoproteins (HDL)", "Total cholesterol / HDL",
16
+ "log(Serum Triglycerides Level) (possibly)","Blood Sugar Level"]
17
 
18
  def create_dataset(feature_id=2):
19
  # Load the diabetes dataset
 
62
  plt.scatter(diabetes_X_test, diabetes_y_test, color="black")
63
  plt.plot(diabetes_X_test, diabetes_y_pred, color="blue", linewidth=3)
64
 
65
+ plt.xlabel(input_data, fontsize=18)
66
+ plt.ylabel("Disease progression", fontsize=18)
67
+
68
  plt.xticks(())
69
  plt.yticks(())
70
 
 
 
71
  return fig, regr.coef_, mse, r2
72
 
73
  title = "Linear Regression Example πŸ“ˆ"
74
+ description = """The example shows how linear regression attempts to draw a straight line that will best minimize the residual sum of squares between the observed responses in the dataset.
75
+
76
+ The diabetes dataset contains baseline variables (features), age, sex, body mass index, average blood pressure, and six blood serum measurements that were obtained for 442 diabetes patients.
77
+ The predictive variable is a quantitative measure of the disease progression one year after the baseline.
78
+
79
+ When selecting a feature from the drop-down menu, a linear regression model is trained for the specific feature and the predictive variable.
80
+ The figure shows a scatter plot of the test set as well as the linear model (line).
81
+ The mean square error and R2 scores are calculated using the test set and they are printed, along with the regression coefficiet of the model.
82
+ """
83
  with gr.Blocks() as demo:
84
  gr.Markdown(f"## {title}")
85
  gr.Markdown(description)
 
91
  with gr.Column():
92
  input_data = gr.Dropdown(choices=feature_names, label="Feature", value="body-mass index")
93
  coef = gr.Textbox(label="Coefficients")
94
+ mse = gr.Textbox(label="Mean Squared Error (MSE)")
95
+ r2 = gr.Textbox(label="R2 score")
96
 
97
  input_data.change(fn=train_model, inputs=[input_data], outputs=[plot, coef, mse, r2], queue=False)
98