Sagar commited on
Commit
6e14a9e
·
1 Parent(s): 21a04b0

Updated Code

Browse files
Files changed (1) hide show
  1. app.py +34 -40
app.py CHANGED
@@ -5,29 +5,19 @@ from sklearn.linear_model import LinearRegression
5
  import gradio as gr
6
 
7
  df=pd.read_csv("mexican_medical_students_mental_health_data.csv")
8
-
9
  df.head()
10
  df.info
11
-
12
  target=df.iloc[:,19:27].sum(axis=1)
13
-
14
  df.insert(43,"gad_total",target)
15
-
16
  df.head()
17
-
18
-
19
-
20
- df.nunique()
21
-
22
-
23
- df.isna().sum()
24
-
25
-
26
-
27
  h_mean=df["height"].mean()
28
  w_mean=df["weight"].mean()
29
  age_mean=df["age"].mean()
30
  g_mode=df["gender"].mode()[0]
 
 
31
  p1=df["phq1"].mode()[0]
32
  p2=df["phq2"].mode()[0]
33
  p3=df["phq3"].mode()[0]
@@ -37,12 +27,7 @@ p6=df["phq6"].mode()[0]
37
  p7=df["phq7"].mode()[0]
38
  p8=df["phq8"].mode()[0]
39
  p9=df["phq9"].mode()[0]
40
-
41
-
42
- p5
43
-
44
-
45
-
46
  df["height"].fillna(h_mean,inplace=True)
47
  df["weight"].fillna(w_mean,inplace=True)
48
  df["age"].fillna(age_mean,inplace=True)
@@ -56,11 +41,26 @@ df["phq6"].fillna(p6,inplace=True)
56
  df["phq7"].fillna(p7,inplace=True)
57
  df["phq8"].fillna(p8,inplace=True)
58
  df["phq9"].fillna(p9,inplace=True)
 
 
59
 
60
  df.isna().sum()
61
 
62
- df["reported_sleep_hours"][0]
63
-
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  from sklearn import preprocessing
66
  le= preprocessing.LabelEncoder()
@@ -68,36 +68,30 @@ df["gender"]=le.fit_transform(df["gender"])
68
  df.head()
69
 
70
 
71
- X=df[["age","gender","height","weight","phq1","phq2","phq3","phq4","phq5","phq6","phq7","phq8","phq9"]]
72
- y=df["gad_total"]
73
 
74
 
 
 
75
 
76
  X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.25,random_state=21)
77
 
78
-
79
  model=LinearRegression()
80
 
81
-
82
-
83
  model.fit(X_train,y_train)
84
  print("Training complete.")
85
 
86
-
87
-
88
  r2_score=model.score(X_test,y_test)
89
  print(r2_score*100,"%")
90
 
 
 
 
91
 
92
- df["gad_total"].max()
93
-
94
-
95
-
96
- df["gad_total"]
97
-
98
-
99
- def greet(name):
100
- return "Hello " + name + "!!"
101
 
102
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
103
- iface.launch()
 
5
  import gradio as gr
6
 
7
  df=pd.read_csv("mexican_medical_students_mental_health_data.csv")
 
8
  df.head()
9
  df.info
 
10
  target=df.iloc[:,19:27].sum(axis=1)
 
11
  df.insert(43,"gad_total",target)
 
12
  df.head()
13
+ df.nunique() #Checking the number of unique values for primary keys or constants
14
+ df.isna().sum()#Missing values
 
 
 
 
 
 
 
 
15
  h_mean=df["height"].mean()
16
  w_mean=df["weight"].mean()
17
  age_mean=df["age"].mean()
18
  g_mode=df["gender"].mode()[0]
19
+ r_mode=df["reported_sleep_hours"].mode()[0]
20
+ n_mode=df["nap_duration"].mode()[0]
21
  p1=df["phq1"].mode()[0]
22
  p2=df["phq2"].mode()[0]
23
  p3=df["phq3"].mode()[0]
 
27
  p7=df["phq7"].mode()[0]
28
  p8=df["phq8"].mode()[0]
29
  p9=df["phq9"].mode()[0]
30
+ r_mode
 
 
 
 
 
31
  df["height"].fillna(h_mean,inplace=True)
32
  df["weight"].fillna(w_mean,inplace=True)
33
  df["age"].fillna(age_mean,inplace=True)
 
41
  df["phq7"].fillna(p7,inplace=True)
42
  df["phq8"].fillna(p8,inplace=True)
43
  df["phq9"].fillna(p9,inplace=True)
44
+ df["reported_sleep_hours"].fillna(r_mode,inplace=True)
45
+ df["nap_duration"].fillna(n_mode,inplace=True)
46
 
47
  df.isna().sum()
48
 
49
+ import datetime
50
+ new=[]
51
+ for i in range(len(df["reported_sleep_hours"])):
52
+ con=datetime.datetime.strptime(str(df["reported_sleep_hours"][i]),"%H:%M")
53
+ t=float(con.minute/60)
54
+ tot=float(con.hour)+t
55
+ new.append(tot)
56
+ df.insert(44,"reported_sleep_in_hours",new)
57
+ new=[]
58
+ for i in range(len(df["nap_duration"])):
59
+ con=datetime.datetime.strptime(str(df["nap_duration"][i]),"%H:%M")
60
+ t=float(con.minute/60)
61
+ tot=float(con.hour)+t
62
+ new.append(tot)
63
+ df.insert(45,"nap_duration_hours",new)
64
 
65
  from sklearn import preprocessing
66
  le= preprocessing.LabelEncoder()
 
68
  df.head()
69
 
70
 
71
+ # In[22]:
 
72
 
73
 
74
+ X=df[["age","gender","height","weight","phq1","phq2","phq3","phq4","phq5","phq6","phq7","phq8","phq9","reported_sleep_in_hours","nap_duration_hours"]]
75
+ y=df["gad_total"]
76
 
77
  X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.25,random_state=21)
78
 
 
79
  model=LinearRegression()
80
 
 
 
81
  model.fit(X_train,y_train)
82
  print("Training complete.")
83
 
 
 
84
  r2_score=model.score(X_test,y_test)
85
  print(r2_score*100,"%")
86
 
87
+ y_pred = model.predict(X_test)
88
+ print('Coefficients: \n', model.coef_)
89
+ print("Mean squared error: %.2f" % np.mean((model.predict(X_test) - y_test) ** 2))
90
 
91
+ def greet(input):
92
+ temp= input.split(",")
93
+ y = model.predict([[temp[0],temp[1],temp[2],temp[3],temp[4],temp[5],temp[6],temp[7],temp[8],temp[9],temp[10],temp[11],temp[12],temp[13],temp[14],temp[15]]])
94
+ y = str(y)
95
+ return y
 
 
 
 
96
 
97
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text").launch(share=True)