<jupyter_start><jupyter_text>Chapter 10===============================<jupyter_code>import pandas as pd
import numpy as np
data_source = "https://stats.idre.ucla.edu/stat/data/binary.csv"
df = pd.read_csv(data_source)

df[:5]
y_data = df['admit'].values.reshape(-1, 1)
x_data = df.ix[:,1:].values

y_data[:5], x_data[:5]
from sklearn import preprocessing

min_max_scaler = preprocessing.MinMaxScaler()
x_data = min_max_scaler.fit_transform(x_data)

x_data[:5]
from sklearn import linear_model, datasets

logreg = linear_model.LogisticRegression(fit_intercept=True)
logreg.fit(x_data, y_data.ravel())

sum(logreg.predict(x_data) == y_data.ravel()) / len(y_data.ravel())
theta = np.append(logreg.intercept_, logreg.coef_.ravel())
theta
theta_file_name = "theta_bin.npy"
np.save(theta_file_name, theta)
np.load(theta_file_name)
min_max = np.vstack((df.ix[:,1:].values.min(axis=0),
                     df.ix[:,1:].values.max(axis=0)))
min_max
min_max_file_name = "min_max.npy"
np.save(min_max_file_name, min_max)
np.load(min_max_file_name)
np.load(theta_file_name)
import pickle

f = open('logicmodel.pkl', 'wb')
f.seek(0)

pickle.dump(logreg, f)
f.close()
fr = open('./logicmodel.pkl', 'rb')
logreg_pickle = pickle.load(fr)

sum(logreg.predict(x_data) == logreg_pickle.predict(x_data)) / len(y_data.ravel())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1805243445692884, 'fraction_numerical': 0.010486891385767791, 'mean_word_length': 6.4222222222222225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '18550', 'license': 'MIT', 'n_tokens_mistral': 556, 'n_tokens_neox': 542, 'n_words': 78, 'path': 'Chapter.10/1.ipynb', 'repo_name': 'alstn2468/Python_For_Machine_Learning', 'size': '1335'}