University Admission Prediction using Keras
Introduction
There are many factors to be considered while applying for Masters in other countries. You need to have a good GRE score, sop(statement of purpose), or(letter of recommendation), etc. If you are from a non-English speaking country you should submit a TOEFL score too. The following dataset consists of the following parameters for rating the chances of admission(0-1).
- GRE Scores ( out of 340 )
- TOEFL Scores ( out of 120 )
- University Rating ( out of 5 )
- Statement of Purpose and Letter of Recommendation Strength ( out of 5 )
- Undergraduate GPA ( out of 10 )
- Research Experience ( either 0 or 1 )
- Chance of Admit ( ranging from 0 to 1 )
The dataset is created by UCLA and the link to download it I gave at the bottom.
https://www.kaggle.com/mohansacharya/graduate-admissions
The following code only consists of building a deep Keras model without performing any EDA.
#import all necessary packages import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from keras.models import Sequential from keras.layers import Dense ,Dropout,BatchNormalization from keras.layers import Dense from keras.wrappers.scikit_learn import KerasRegressor
#dropping serial number as it is not necessary df=df.drop("Serial No.",axis=1) #splitting into train and test data X=np.asarray(df.drop("Chance of Admit",axis=1)) Y=np.asarray(df[""Chance of Admit "]) X_train, X_test, y_train, y_test = train_test_split( X,Y, test_size=0.2, random_state=0) #Normalisation from sklearn.preprocessing import MinMaxScaler scaler = MinMaxScaler() X_train=scaler.fit_transform(X_train) X_test=scaler.fit_transform(X_test)
Building the Model
# define keras model def baseline_model(): # create model model = Sequential() model.add(Dense(16, input_dim=7, activation='relu')) model.add(Dense(16, input_dim=7, activation='relu')) model.add(Dense(16, input_dim=7, activation='relu')) model.add(Dense(16, input_dim=7, activation='relu')) model.add(Dense(1)) # Compile model model.compile(loss='mean_squared_error', optimizer='adam') return model
estimator = KerasRegressor(build_fn=baseline_model, epochs=20, batch_size=3, verbose=1) prediction = estimator.predict(X_test) from sklearn.metrics import accuracy_score print(prediction)
[0.65, 0.7, 0.78, 0.6, 0.71, 0.57, 0.7, 0.62, 0.86, 0.93, 0.47, 0.9, 0.67, 0.35, 0.86, 0.59, 0.56, 0.78, 0.51, 0.73, 0.9, 0.83, 0.62, 0.31, 0.81, 0.5, 0.34, 0.63, 0.92, 0.59, 0.62, 0.74, 0.73, 0.51, 0.77, 0.77, 0.63, 0.88, 0.61, 0.95, 0.73, 0.65, 0.71, 0.82, 0.82, 0.64, 0.54, 0.69, 0.58, 0.58, 0.66, 0.77, 0.59, 0.9, 0.7, 0.7, 0.75, 0.73, 0.75, 0.85, 0.77, 0.37, 0.61, 0.44, 0.87, 0.81, 0.67, 0.9, 0.74, 0.76, 0.56, 0.84, 0.84, 0.53, 0.93, 0.55, 0.63, 0.63, 0.92, 0.44] is almost similar to test value. [0.71 0.7 0.79 0.73 0.72 0.48 0.77 0.71 0.9 0.94 0.58 0.89 0.72 0.57 0.78 0.42 0.64 0.84 0.63 0.72 0.9 0.83 0.57 0.47 0.85 0.67 0.44 0.54 0.92 0.62 0.68 0.73 0.73 0.61 0.55 0.74 0.64 0.89 0.73 0.95 0.71 0.72 0.75 0.76 0.86 0.7 0.39 0.79 0.61 0.64 0.71 0.8 0.61 0.89 0.68 0.79 0.78 0.52 0.76 0.88 0.74 0.49 0.65 0.59 0.87 0.89 0.81 0.9 0.8 0.76 0.68 0.87 0.68 0.64 0.91 0.61 0.69 0.62 0.93 0.43]
If you plot y_test and prediction, they coincide.
We can further verify by calculating the mean error.
train_error = np.abs(y_test - prediction) mean_error = np.mean(train_error) print("mean_error: ",mean_error) #0.06197833371162416
Since the error is less than 0.1, our model predicts every accurately.
Leave a Reply