<jupyter_start><jupyter_text>MLP classifier on a real dataset 42k rows and 700+ columns<jupyter_code>%matplotlib inline

import matplotlib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import datasets ## imports datasets from scikit-learn
from sklearn.model_selection import train_test_split
from sklearn import model_selection
from sklearn.decomposition import PCA

from sklearn.preprocessing import scale
data=pd.read_csv("Digits1.csv") #classify digits on basis of attributes 
data.head(5)
X= data.drop("label", axis=1) #predictors
Y = data["label"] #response 
#split the data
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = .25, random_state=25) #25% hold out for testing
#Lets derive PCs from the predictor/ X variables
#Scaling the values
X_train = scale(X_train)
X_test=scale(X_test)
pca = PCA(n_components=80) #given the large number of predictors, let derive 80 pcs 
XP=pca.fit(X_train)
#The amount of variance that each PC explains
var= XP.explained_variance_ratio_
var
plt.plot(var)
# first 45 pcs explain the maximum variance in the dataset
# fit a new PCA and store results along with labels in a data farame 

pca = PCA(n_components=45) #
pca.fit(X_train)
PCtrain = pd.DataFrame(pca.transform(X_train))
PCtrain['label'] = data['label']


PCtest = pd.DataFrame(pca.transform(X_test)) #testing
PCtest['label'] = data['label']
# get X and y from our PCA transformed dataframe
#y1 = PCtrain['label'][0:20000]
#X1=PCtrain.drop('label', axis=1)[0:20000]
from sklearn.neural_network import MLPClassifier
clf = MLPClassifier(activation = 'logistic',solver='lbfgs',hidden_layer_sizes=(3000,), alpha=0.0001,random_state=1) #specify activation function
#clf.fit(X1, y1)
y2 = PCtrain['label']
X2=PCtrain.drop('label', axis=1)
clf.fit(X2, y2)
y3 = PCtest['label']
X3=PCtest.drop('label', axis=1)
Y_pred = clf.predict(X3) 
from sklearn.metrics import confusion_matrix
confusion_matrix = confusion_matrix(y3, Y_pred)
confusion_matrix
import h2o
h2o.init()
iris = h2o.import_file(path="https://github.com/h2oai/h2o-3/raw/master/h2o-r/h2o-package/inst/extdata/iris_wheader.csv")
iris.describe()
iris.head(4)
trainFrame = h2o.import_file(path="F:\Python_ML\Course6_Python4DS\MLData_n_Script\section11\Digits1.csv")
trainFrame.head(5)
trainFrame.shape
g=h2o.import_file(path="F:\Python_ML\Course6_Python4DS\MLData_n_Script\section11\glassClass.csv")
g.describe()
g.head(5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11586596689543803, 'fraction_numerical': 0.03270084779975777, 'mean_word_length': 6.719626168224299, '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': '271730', 'license': 'MIT', 'n_tokens_mistral': 956, 'n_tokens_neox': 903, 'n_words': 221, 'path': 'section7/.ipynb_checkpoints/Section12_Lecture113-checkpoint.ipynb', 'repo_name': 'PacktPublishing/Regression-Modeling-With-Statistics-and-Machine-Learning-in-Python', 'size': '2477'}