import pandas as pd
import numpy as np
import pandas as pd
import numpy as np
import random
alp=['a','b','c','d','e','f','g','h','i','j']
d={}
ls=[]
for k in range(0,10):
matrix=[]
ls=[]
for i in range(7):
row=[]
for j in range(7):
row.append(random.randint(0,1))
matrix.append(row)
d[alp[k]]=np.squeeze(np.asarray(matrix))
d
s=pd.DataFrame(columns=['0','1','2','3','4','5','6','label'],index=list(range(70)))
i=0
for j in range(len(d)):
for m in range(7):
for k in range(7):
s.iloc[i,k]=(d[list(d.keys())[j]][m][k])
s.iloc[i,k+1]=list(d.keys())[j]
i=i+1
# i=i+7
x=s[['0','1','2','3','4','5','6']]
y=s['label']
# Random Forest
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.3)
clf = RandomForestClassifier(max_depth=50, random_state=0)
clf.fit(X_train,y_train)
y_pred=clf.predict(X_test)
from sklearn import metrics
# Model Accuracy, how often is the classifier correct?
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
#SVM Classifier
from sklearn.svm import SVC
svclassifier = SVC(kernel='linear')
svclassifier.fit(X_train, y_train)
y_pred = svclassifier.predict(X_test)
from sklearn.metrics import classification_report, confusion_matrix
print(confusion_matrix(y_test,y_pred))
print(classification_report(y_test,y_pred))
from sklearn import metrics
# Model Accuracy, how often is the classifier correct?
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
#MLP Classifier
from sklearn.neural_network import MLPClassifier
#Initializing the MLPClassifier
classifier = MLPClassifier(hidden_layer_sizes=(150,100,50), max_iter=300,activation = 'relu',solver='adam',random_state=1)
#Fitting the training data to the network
classifier.fit(X_train, y_train)
#Predicting y for X_val
y_pred = classifier.predict(X_test)
from sklearn import metrics
# Model Accuracy, how often is the classifier correct?
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))