<jupyter_start><jupyter_text>TASK 1: IMPORT LIBRARIES AND DATASET<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# read the csv file 
admission = pd.read_csv('Admission_Predict.csv')
admission.head()
# drop the serial no.
admission.drop('Serial No.', axis = 1, inplace = True)
admission<jupyter_output><empty_output><jupyter_text>TASK 2: PERFORM EXPLORATORY DATA ANALYSIS<jupyter_code># checking the null values
admission.isnull().sum()
# Check the dataframe information
admission.info()
# Statistical summary of the dataframe
admission.describe()
# Grouping by University ranking 
university = admission.groupby(by = 'University Rating').mean()
university<jupyter_output><empty_output><jupyter_text>TASK 3: PERFORM DATA VISUALIZATION<jupyter_code>admission.hist(bins = 30, figsize = (20,20), color = 'red')
sns.pairplot(admission)

corr_matrix = admission.corr()
plt.figure(figsize = (12,12))
sns.heatmap(corr_matrix, annot = True)
plt.show()<jupyter_output><empty_output><jupyter_text>TASK 4: CREATE TRAINING AND TESTING DATASET<jupyter_code>x = admission.drop(columns = ['Chance of Admit'])
y = admission['Chance of Admit']
x = np.array(x)
y = np.array(y)
y = y.reshape(-1, 1)
import sklearn
# scaling the data before training the model
from sklearn.preprocessing import StandardScaler, MinMaxScaler
scaler_x = StandardScaler()
x = scaler_x.fit_transform(x)
scaler_y = StandardScaler()
y = scaler_y.fit_transform(y)
# spliting the data in to test and train sets
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.15)<jupyter_output><empty_output><jupyter_text>TASK 5: TRAIN AND EVALUATE A LINEAR REGRESSION MODEL<jupyter_code>from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, accuracy_score
LinearRegression_model = LinearRegression()
LinearRegression_model.fit(x_train, y_train)
accuracy_LinearRegression = LinearRegression_model.score(x_test, y_test)
print(accuracy_LinearRegression)<jupyter_output>0.8305648152911806<jupyter_text>TASK 6: TRAIN AND EVALUATE AN ARTIFICIAL NEURAL NETWORK<jupyter_code>import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Dense, Activation, Dropout
from tensorflow.keras.optimizers import Adam

ANN_model = keras.Sequential()
ANN_model.add(Dense(50, input_dim = 7))
ANN_model.add(Activation('relu'))
ANN_model.add(Dense(150))
ANN_model.add(Activation('relu'))
ANN_model.add(Dropout(0.5))
ANN_model.add(Dense(150))
ANN_model.add(Activation('relu'))
ANN_model.add(Dropout(0.5))
ANN_model.add(Dense(50))
ANN_model.add(Activation('linear'))
ANN_model.add(Dense(1))
ANN_model.compile(loss = 'mse', optimizer = 'adam')
ANN_model.summary()
ANN_model.compile(optimizer='Adam', loss='mean_squared_error')
epochs_hist = ANN_model.fit(x_train, y_train, epochs = 100, batch_size = 20, validation_split = 0.2)
result = ANN_model.evaluate(x_test, y_test)
accuracy_ANN = 1 - result
print("Accuracy : {}".format(accuracy_ANN)) 
epochs_hist.history.keys() 
plt.plot(epochs_hist.history['loss'])
plt.title('Model Loss Progress During Training')
plt.xlabel('Epoch')
plt.ylabel('Training Loss')
plt.legend(['Training Loss'])<jupyter_output><empty_output><jupyter_text>TASK 7: TRAIN AND EVALUATE A DECISION TREE AND RANDOM FOREST MODELS<jupyter_code># Decision tree builds regression or classification models in the form of a tree structure. 
# Decision tree breaks down a dataset into smaller subsets while at the same time an associated decision tree 
# is incrementally developed. 
# The final result is a tree with decision nodes and leaf nodes.
# Great resource: https://www.saedsayad.com/decision_tree_reg.htm

from sklearn.tree import DecisionTreeRegressor
DecisionTree_model = DecisionTreeRegressor()
DecisionTree_model.fit(x_train, y_train) 
accuracy_DecisionTree = DecisionTree_model.score(x_test, y_test)
print(accuracy_DecisionTree) 
# Many decision Trees make up a random forest model which is an ensemble model. 
# Predictions made by each decision tree are averaged to get the prediction of random forest model.
# A random forest regressor fits a number of classifying decision trees on various sub-samples of the 
# dataset and uses averaging to improve the predictive accuracy and control over-fitting. 

from sklearn.ensemble import RandomForestRegressor
RandomForest_model = RandomForestRegressor()
RandomForest_model.fit(x_train, np.ravel(y_train))
accuracy_RandomForest = RandomForest_model.score(x_test, y_test)
print(accuracy_RandomForest)<jupyter_output>0.7849518672867184<jupyter_text>TASK 8: CALCULATE REGRESSION MODEL KPIs<jupyter_code>y_predict = LinearRegression_model.predict(x_test)
plt.plot(y_test, y_predict, '^', color = 'red') 
y_predict_orig = scaler_y.inverse_transform(y_predict)
y_test_orig = scaler_y.inverse_transform(y_test)
plt.plot(y_test_orig, y_predict_orig, '^', color = 'red')
k = x_test.shape[1] 
n = len(x_test)
n 
from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error
from math import sqrt

RMSE = float(format(np.sqrt(mean_squared_error(y_test_orig, y_predict_orig)),'.3f'))
MSE = mean_squared_error(y_test_orig, y_predict_orig)
MAE = mean_absolute_error(y_test_orig, y_predict_orig)
r2 = r2_score(y_test_orig, y_predict_orig)
adj_r2 = 1-(1-r2)*(n-1)/(n-k-1)

print('RMSE =',RMSE, '\nMSE =',MSE, '\nMAE =',MAE, '\nR2 =', r2, '\nAdjusted R2 =', adj_r2)<jupyter_output>RMSE = 0.053 
MSE = 0.0027878157429439693 
MAE = 0.03964752601300867 
R2 = 0.8305648152911806 
Adjusted R2 = 0.8128626318141399
{'fraction_non_alphanumeric': 0.10299892895394502, 'fraction_numerical': 0.03123884327026062, 'mean_word_length': 7.26401179941003, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '171426', 'license': 'MIT', 'n_tokens_mistral': 2184, 'n_tokens_neox': 1980, 'n_words': 462, 'path': 'Python/university_admission_prediction/Graduate_Admission_Prediction.ipynb', 'repo_name': 'Elyrie/Hacktoberfest-2021', 'size': '5602'}