-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project_UK_final (1).py
158 lines (89 loc) · 3.25 KB
/
Project_UK_final (1).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python
# coding: utf-8
# In[24]:
#Importing all required Libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from pandas import Series
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import auc, accuracy_score, confusion_matrix, mean_squared_error
from sklearn.model_selection import cross_val_score, GridSearchCV, KFold, RandomizedSearchCV, train_test_split
from sklearn.tree import DecisionTreeClassifier
# In[25]:
univdata = pd.read_csv("C:/Users/Admin/Desktop/Myprojectdata.csv", delimiter = ",",encoding='unicode_escape' )
univdata
trimColNames = [name.strip() for name in univdata.columns]
univdata.columns = trimColNames
# In[ ]:
univdata['UnivName'] = univdata['UnivName'].astype(str)
print(univdata.dtypes)
univdata.shape
univdata.describe()
univdata = pd.get_dummies(univdata)
labels = np.array(univdata['UK Rank'])
univdata_list = list(univdata.columns)
univdata = np.array(univdata)
# In[174]:
#Finding the Correlation Matrix between the predicted and the output Variable
correlation_matrix = univdata.iloc[:,:].corr().round(2)
sns.heatmap(data=correlation_matrix, annot=True)
# Year, UK Rank and World class rank have a strong relation and hence can help in finding best university
# In[175]:
# Determining the Public and private universities as per UK Ranking
sns.catplot(data = univdata, x = "Type", y = "UK Rank")
# Determining the Public and private universities as per UK Ranking
sns.catplot(data = univdata, x = "Type", y = "World Class Rank")
#Result - There are less Private universities which has good world ranking
sns.displot(univdata['Avg fees UG (in pounds)'])
# In[210]:
X = univdata[["UK Rank", "World Class Rank"]]
# Visualize data point
plt.scatter(X["UK Rank"], X["World Class Rank"], c="blue")
plt.xlabel("UK Rank")
plt.ylabel("World Class Rank")
plt.show()
# In[211]:
K=3
# select random observation as a centriod
Centroids = (X.sample(n=K))
plt.scatter(X["UK Rank"], X["World Class Rank"], c="blue")
plt.scatter(Centroids["UK Rank"], Centroids["World Class Rank"], c="red")
plt.xlabel("UK Rank")
plt.ylabel("World Class Rank")
plt.show()
# In[213]:
Centroids
# In[26]:
X = univdata["UK Rank"]
Y = univdata["World Class Rank"]
plt.plot(X, Y)
plt.xlabel('x - axis')
# naming the y axis
plt.ylabel('y - axis')
plt.title('Line Graph')
plt.show()
# In[27]:
x = univdata.iloc[:,4:6] # 1t for rows and second for columns
x
# In[28]:
identified_clusters = kMeans.fit_predict(x)
identified_clusters
# In[29]:
from sklearn.cluster import KMeans
kMeans = KMeans(3)
kMeans.fit(identified_clusters)
# In[244]:
data_with_clusters = data.copy()
data_with_clusters['Clusters'] = identified_clusters
plt.scatter(data_with_clusters['UK Rank'],data_with_clusters['World Class Rank'],c=data_with_clusters['Clusters'],cmap='rainbow')
# In[207]:
#Training the Model
train_univdata, test_univdata,train_labels, test_labels = train_test_split(univdata, labels, test_size = 0.30, random_state = 1899)
print('Training Univdata Shape:', a_train.shape)
print('Testing Univdata Shape:', b_train.shape)
print('Training Labels Shape:', train_labels.shape)
print('Testing Labels Shape:', test_labels.shape)
# In[ ]: