<jupyter_start><jupyter_text>" With Linear Regression, predict the chance of getting admitted in XYZ college "     - <NAME> (@racyriaz)      Hey there, Welcome! In this notebook we shall solve a problem on predicting the chance/probability of a candidate to get admission in XYZ college given his CGPA, TOFEL, GRE score and his Research work. Importing all the required libraries<jupyter_code>import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
from scipy import stats
from sklearn import linear_model
from sklearn.metrics import r2_score,mean_squared_error<jupyter_output><empty_output><jupyter_text>Filepath of the dataset<jupyter_code>filepath = r"C:/Users/riaz/Desktop/Admission_Predict.csv"
df = pd.read_csv(filepath,index_col='Serial No.')<jupyter_output><empty_output><jupyter_text>Checking for Null values<jupyter_code>df.isnull().sum()<jupyter_output><empty_output><jupyter_text>Renaming columns and plotting thier Karl Pearson's Coefficients using corr() and heatmap<jupyter_code>df.columns=['gre','tofel','ranking','sop','lor','cgpa','research','admit']
sns.heatmap(df.corr(),annot=True)
df.corr().admit<jupyter_output><empty_output><jupyter_text>Cleaning the dataset Taking only the required feature that has high corr with the admit column<jupyter_code>new_df = df[['gre','cgpa','tofel','admit']]
sns.heatmap(new_df.corr(),annot=True)<jupyter_output><empty_output><jupyter_text>Finding outliers<jupyter_code>def fourplots(listofplots,row,col,comment,data):
    fig, axs = plt.subplots(1, 4,figsize=(15,3))
    sub = []
    n = 0
    fig.suptitle(comment,fontsize=20,color='Gray')
    for i in listofplots:
        fig = sns.distplot(data[i],ax=axs[n])
        sub.append(axs)
        n+=1<jupyter_output><empty_output><jupyter_text>Before removing outliers<jupyter_code>list_of_plots = ['gre','cgpa','tofel','admit']
row = 1
col = 3
comment = 'Before removing outliers'
fourplots(list_of_plots,row,col,comment,new_df)
z = np.abs(stats.zscore(new_df))<jupyter_output><empty_output><jupyter_text>After removing outliers<jupyter_code>clean = new_df[(z < 3).all(axis=1)]
comment = 'After removing outliers'
fourplots(list_of_plots,row,col,comment,clean)<jupyter_output><empty_output><jupyter_text>spliting X and Y terms<jupyter_code>X = clean.drop(['admit'],axis=1).values
y = clean['admit'].values
y.shape<jupyter_output><empty_output><jupyter_text>Preprocessing the data<jupyter_code>from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(X)
X_scaled = scaler.transform(X)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.33, random_state=42)<jupyter_output><empty_output><jupyter_text>Building the model<jupyter_code>reg = linear_model.LinearRegression()
reg.fit(X_train,y_train)
y_test.shape<jupyter_output><empty_output><jupyter_text>Predicting the values of X_test<jupyter_code>pred = reg.predict(X_test)<jupyter_output><empty_output><jupyter_text>Checking the score of predicted values<jupyter_code>reg.score(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Visualising the predictions with true values<jupyter_code>plt.figure(figsize=(20,8))
y=pred
y1=y_test
x=np.arange(1, 133, 1)
x1=np.arange(0,133,10)
plt.plot(x,y,color='r',marker='o',label='Predicted',linestyle='dashed')
plt.plot(x,y1,color='g',label='Actual')
plt.xticks(x1)
plt.gca().legend(('Predicted','Test'))
plt.xlabel('Cases',fontsize=20)
plt.ylabel('Chance of getting admitted',fontsize=20)
plt.title('Predictions Vs True Values',fontsize=25)
plt.grid()
plt.ioff()<jupyter_output><empty_output><jupyter_text>Model Evaluations<jupyter_code>print("R2 score of our Model: ", end=" ")
print(r2_score(y_test,pred))
print("RMSE of our model: " ,end=' ')
print(np.sqrt(mean_squared_error(y_test,pred)))<jupyter_output>R2 score of our Model:  0.7492225017821701
RMSE of our model:  0.07177837246915582
{'fraction_non_alphanumeric': 0.130997715156131, 'fraction_numerical': 0.020817466362020816, 'mean_word_length': 8.899497487437186, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '186361', 'license': 'Unlicense', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1445, 'n_words': 256, 'path': 'Machine Learning/.ipynb_checkpoints/Admission_linear_regression-checkpoint.ipynb', 'repo_name': 'racyriaz/myPrograms', 'size': '3945'}