# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd

df = pd.read_csv("College.csv")

df.columns

# +
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder

X, y = df.iloc[:, 1:].values, df.iloc[:, 0].values

# Encode label category
# male -> 1
# female -> 0

target_encoder = LabelEncoder()
y = target_encoder.fit_transform(y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)
print(X_train.shape)

# +
from sklearn.svm import LinearSVC,SVC
classifier = LinearSVC()


classifier.fit(X_train,y_train)

y_predict = classifier.predict(X_test)

classifier.score(X_test,y_test)

# +
from sklearn.metrics import confusion_matrix

print(confusion_matrix(y_predict,y_test))
# -

classifier = SVC()
classifier.fit(X_train,y_train)
classifier.score(X_test,y_test)

from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import StandardScaler

scaler = StandardScaler()
X, y = df.iloc[:, 1:].values, df.iloc[:, 0].values
X = scaler.fit_transform(X)

# +
target_encoder = LabelEncoder()
y = target_encoder.fit_transform(y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)
print(X_train.shape)
# -

classifier = SVC()
classifier.fit(X_train,y_train)
classifier.score(X_test,y_test)

import numpy as np
from sklearn.model_selection import StratifiedShuffleSplit

C_range = np.logspace(-2, 10, 13)
gamma_range = np.logspace(-9, 3, 13)
param_grid = dict( gamma=gamma_range,C=C_range)
grid = GridSearchCV(SVC(), param_grid=param_grid)
grid.fit(X_train, y_train)

print("The best parameters are %s with a score of %0.2f"
      % (grid.best_params_, grid.best_score_))





StarcoderdataJupyterScriptsDedupFiltered