Upload 2 files
Browse files- 1812_159_252.py +101 -0
- Raw Data.csv +0 -0
1812_159_252.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""1812.159.252
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/18Q9tMQvVHXk2Rs_3EoKpdRhFuOyv4iDk
|
8 |
+
"""
|
9 |
+
|
10 |
+
import numpy as np
|
11 |
+
import pandas as pd
|
12 |
+
import matplotlib.pyplot as plt
|
13 |
+
import seaborn as sns
|
14 |
+
import warnings
|
15 |
+
warnings.filterwarnings('ignore')
|
16 |
+
|
17 |
+
df = pd.read_csv('/content/Raw Data.csv')
|
18 |
+
|
19 |
+
df.info()
|
20 |
+
|
21 |
+
cols_index = list(range(7, 14)) + list(range(16, 26)) + list(range(28,37))
|
22 |
+
|
23 |
+
df.drop(columns=df.columns[cols_index], inplace=True)
|
24 |
+
|
25 |
+
df.info()
|
26 |
+
|
27 |
+
df.columns = df.columns.str.replace(r'^\d+\.\s*','', regex=True)
|
28 |
+
df.rename(columns = {'Did you receiver a waiver or scholarship at your university?': 'Waiver/Scholarship'}, inplace=True)
|
29 |
+
|
30 |
+
df.info()
|
31 |
+
|
32 |
+
value_cols = ['Anxiety Value', 'Stress Value', 'Depression Value']
|
33 |
+
|
34 |
+
for col in value_cols:
|
35 |
+
plt.figure(figsize=(10,6))
|
36 |
+
plt.title(f'{col}, Distribution')
|
37 |
+
sns.histplot(data=df, x=col, bins=10)
|
38 |
+
plt.show()
|
39 |
+
|
40 |
+
label_cols = ['Anxiety Label', 'Stress Label', 'Depression Label']
|
41 |
+
|
42 |
+
for col in label_cols:
|
43 |
+
data = df[col].value_counts().reset_index()
|
44 |
+
plt.figure(figsize=(10,6))
|
45 |
+
plt.title(f'{col} Distribution')
|
46 |
+
sns.barplot(data=data, x=col, y='count', palette='viridis', width=.4)
|
47 |
+
plt.xticks(rotation=45)
|
48 |
+
plt.xlabel('')
|
49 |
+
plt.ylabel('')
|
50 |
+
plt.show()
|
51 |
+
|
52 |
+
features = df.drop(columns=value_cols+label_cols).columns
|
53 |
+
|
54 |
+
for label in label_cols:
|
55 |
+
label_name = label.split(' ')[0]
|
56 |
+
print(f'\n{label_name} Analysis\n')
|
57 |
+
for col in features:
|
58 |
+
pivot_table = pd.crosstab(df[col], df[label])
|
59 |
+
pivot_tabel = pivot_table.div(pivot_table.sum(axis=1), axis=0) * 100
|
60 |
+
plt.figure(figsize=(10,8))
|
61 |
+
sns.heatmap(pivot_table, annot=True, fmt='.2f', cmap='YlGnBu')
|
62 |
+
plt.title(f'{label_name} vs {col}')
|
63 |
+
plt.xlabel('')
|
64 |
+
plt.ylabel('')
|
65 |
+
plt.yticks(rotation=0)
|
66 |
+
plt.show()
|
67 |
+
|
68 |
+
from sklearn.preprocessing import OrdinalEncoder
|
69 |
+
|
70 |
+
df.drop(columns=value_cols, inplace=True)
|
71 |
+
|
72 |
+
ordinal_encoder = OrdinalEncoder()
|
73 |
+
df[df.columns] = ordinal_encoder.fit_transform(df[df.columns])
|
74 |
+
|
75 |
+
df.head()
|
76 |
+
|
77 |
+
for label in label_cols:
|
78 |
+
cols = list(features).copy()
|
79 |
+
cols.append(label)
|
80 |
+
data = df[cols].corr()
|
81 |
+
plt.figure(figsize=(10,8))
|
82 |
+
sns.heatmap(data, annot=True, fmt='.3f', cmap='coolwarm')
|
83 |
+
plt.title(f'{label} Correlation')
|
84 |
+
plt.show()
|
85 |
+
|
86 |
+
from sklearn.model_selection import train_test_split
|
87 |
+
from sklearn.ensemble import RandomForestClassifier
|
88 |
+
from sklearn.metrics import accuracy_score
|
89 |
+
|
90 |
+
print('Model Accuracy')
|
91 |
+
for label in label_cols:
|
92 |
+
X = df.drop(columns=label_cols)
|
93 |
+
y = df[label]
|
94 |
+
|
95 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .2, random_state = 0)
|
96 |
+
|
97 |
+
model = RandomForestClassifier(random_state=0, n_estimators=30, max_depth=8)
|
98 |
+
model.fit(X_train, y_train)
|
99 |
+
preds = model.predict(X_test)
|
100 |
+
|
101 |
+
print(f'{label}: {accuracy_score(y_test, preds) * 100:.2f}%')
|
Raw Data.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|