<jupyter_start><jupyter_text>Part 1: Visualizing the Data<jupyter_code>data_file = "../data/graduate_admission.csv"
data = pd.read_csv(data_file)
# Column keys
SER_KEY = "Serial No."
GRE_KEY = "GRE Score"
TOEFL_KEY = "TOEFL Score"
UNI_KEY = "University Rating"
SOP_KEY = "SOP"
LOR_KEY = "LOR " # Note the trailing space character
CGPA_KEY = "CGPA"
RES_KEY = "Research"
CHANCE_ADMIT_KEY = "Chance of Admit"
data<jupyter_output><empty_output><jupyter_text>GRE Scores<jupyter_code>data.hist(column=GRE_KEY, bins=40)
print(f"Mean GRE score: {data[GRE_KEY].mean()}")
print(f"Median GRE score: {data[GRE_KEY].median()}")
print(f"Min GRE score: {data[GRE_KEY].min()}")
print(f"Max GRE score: {data[GRE_KEY].max()}")<jupyter_output>Mean GRE score: 316.472
Median GRE score: 317.0
Min GRE score: 290
Max GRE score: 340<jupyter_text>TOEFL Scores<jupyter_code>data.hist(column=TOEFL_KEY, bins=20)
print(f"Mean TOEFL score: {data[TOEFL_KEY].mean()}")
print(f"Median TOEFL score: {data[TOEFL_KEY].median()}")
print(f"Min TOEFL score: {data[TOEFL_KEY].min()}")
print(f"Max TOEFL score: {data[TOEFL_KEY].max()}")<jupyter_output>Mean TOEFL score: 107.192
Median TOEFL score: 107.0
Min TOEFL score: 92
Max TOEFL score: 120<jupyter_text>University Ratings<jupyter_code>data.hist(column=UNI_KEY, bins=5)
print(f"Mean University rating: {data[UNI_KEY].mean()}")
print(f"Median University rating: {data[UNI_KEY].median()}")
print(f"Min University rating: {data[UNI_KEY].min()}")
print(f"Max University rating: {data[UNI_KEY].max()}")<jupyter_output>Mean University rating: 3.114
Median University rating: 3.0
Min University rating: 1
Max University rating: 5<jupyter_text>SOP<jupyter_code>data.hist(column=SOP_KEY, bins=10)
print(f"Mean SOP: {data[SOP_KEY].mean()}")
print(f"Median SOP: {data[SOP_KEY].median()}")
print(f"Min SOP: {data[SOP_KEY].min()}")
print(f"Max SOP: {data[SOP_KEY].max()}")<jupyter_output>Mean SOP: 3.374
Median SOP: 3.5
Min SOP: 1.0
Max SOP: 5.0<jupyter_text>LOR<jupyter_code>data.hist(column=LOR_KEY, bins=10)
print(f"Mean LOR: {data[LOR_KEY].mean()}")
print(f"Median LOR: {data[LOR_KEY].median()}")
print(f"Min LOR: {data[LOR_KEY].min()}")
print(f"Max LOR: {data[LOR_KEY].max()}")<jupyter_output>Mean LOR: 3.484
Median LOR: 3.5
Min LOR: 1.0
Max LOR: 5.0<jupyter_text>CGPA<jupyter_code>data.hist(column=CGPA_KEY, bins=10)
print(f"Mean CGPA: {data[CGPA_KEY].mean()}")
print(f"Median CGPA: {data[CGPA_KEY].median()}")
print(f"Min CGPA: {data[CGPA_KEY].min()}")
print(f"Max CGPA: {data[CGPA_KEY].max()}")<jupyter_output>Mean CGPA: 8.576440000000003
Median CGPA: 8.56
Min CGPA: 6.8
Max CGPA: 9.92<jupyter_text>AnalysisAll of the features seem to be normally distributed.  Part 2: Predictive Models  Data Preprocessing<jupyter_code># Separate the data into training and validation sets
train_full = data.iloc[:400, :]
test_full = data.iloc[400:500, :]

# The last column, chance of admit, is how the accuracy of a model will be measured
train_X = train_full.iloc[:, 1:8]
train_y = train_full.iloc[:, 8]

test_X = test_full.iloc[:, 1:8]
test_y = test_full.iloc[:, 8]
# Standardized version of data
std_train_X = (train_X - train_X.mean()) / train_X.std()
std_test_X = (test_X - test_X.mean()) / test_X.std()<jupyter_output><empty_output><jupyter_text>PCA Analysis<jupyter_code># Dimensionality reduction
pca = PCA(n_components=3)
pca.fit_transform(train_X)
pca.explained_variance_ratio_
abs(pca.components_)<jupyter_output><empty_output><jupyter_text>It appears that GRE scores have the most variance, followed by TOEFL scores and University Rating<jupyter_code>def run_classifiers(classifiers, train_X, train_y, test_X, test_y):
    """
    Fits each classifier to the training data and runs it on the test data.
    Prints out the training and test mean squared errors. 
    """
    # Baseline: a random predictor that assigns a probability of 0.5 to each data point
    rand_train_mse = mean_squared_error(train_y.values, np.full(400, 0.5))
    rand_test_mse = mean_squared_error(test_y.values, np.full(100, 0.5))
    print(f"Random training MSE = {rand_train_mse}")
    print(f"Random test MSE = {rand_test_mse}")
    print()
    
    for clf in classifiers:
        print(f"Classifier: {clf}")
        clf.fit(train_X, train_y)
        train_mse = mean_squared_error(train_y.values, clf.predict(train_X))
        test_mse = mean_squared_error(test_y.values, clf.predict(test_X))

        print(f"Training MSE = {train_mse}")
        print(f"Validation MSE = {test_mse}")
        print()

classifiers = [
    LinearRegression(),
    BayesianRidge(),
    SVR(gamma="scale")
]
run_classifiers(classifiers, train_X, train_y, test_X, test_y)<jupyter_output>Random training MSE = 0.0706195
Random test MSE = 0.062769

Classifier: LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)
Training MSE = 0.003986893243246914
Validation MSE = 0.001843174437604737

Classifier: BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, compute_score=False, copy_X=True,
              fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06, n_iter=300,
              normalize=False, tol=0.001, verbose=False)
Training MSE = 0.00399161762002594
Validation MSE = 0.0018401359095189074

Classifier: SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma='scale',
    kernel='rbf', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
Training MSE = 0.00698123868861436
Validation MSE = 0.00537288641133361
{'fraction_non_alphanumeric': 0.14132643635691852, 'fraction_numerical': 0.05357472750785147, 'mean_word_length': 6.123684210526315, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '556220', 'license': 'MIT', 'n_tokens_mistral': 2395, 'n_tokens_neox': 2166, 'n_words': 443, 'path': 'code/graduate_admission.ipynb', 'repo_name': 'and-le/acharya-ga', 'size': '5413'}