Posts

Checking Vowels in String

 Checking Vowels in String def CheckVovels(var): Vovels=['a','e','i','o','u','A','E','I','O','U'] count=0 for i in range(0,len(Vovels),1): if Vovels[i]==var: return True else: count=count+1 if count>0: return False text=input("Enter something about you:") List=text.split(); for i in range(0,len(List),1): if CheckVovels(List[i][0]): List[i]=List[i]+"hey" else: temp1=List[i]; temp2=List[i][0]; temp3=temp1.replace(temp2,''); List[i]=temp3 List[i]=List[i]+"hey" print(List)

Reflex Cleaning Agent

Reflex Cleaning Agent  percept=["dirty","dirty"] action=["Move Right","Move Left","Clean Dirt"] class Agent: def __init__(self): self.position=0 self.currentAction=0 self.runAgent() def runAgent(self): self.getAction(percept[0]) def getAction(self,cPercept): if(cPercept=="dirty"): self.currentAction=action[2] self.updateRooms() elif(cPercept=="clean"): if(self.position==0): self.currentAction=action[0] self.updatePosition() elif(self.position==1): self.currentAction=action[1] self.updatePosition() def updatePosition(self): if(self.currentAction==action[0]): self.position=1 self.getAction(percept[1]) elif(self.currentAction==action[1]): self.position=0 def updateRooms(self):

Principle Component Analysis (PCA) without using function

 PCA without using function import matplotlib.pyplot as plt from sklearn import datasets from sklearn.preprocessing import MinMaxScaler import numpy as np iris=datasets.load_iris() data=np.array(iris.data[:10,:2]) scaler=MinMaxScaler() scaler.fit(data) data=scaler.transform(data) print(data) irisDataset=data irisDataset_mean = irisDataset - np.mean(irisDataset , axis = 0) cov_mat = np.cov(irisDataset_mean , rowvar = False) eigen_values , eigen_vectors = np.linalg.eigh(cov_mat) sorted_index = np.argsort(eigen_values)[::-1] sorted_eigenvalue = eigen_values[sorted_index] sorted_eigenvectors = eigen_vectors[:,sorted_index] n_components = 2 eigenvector_subset = sorted_eigenvectors[:,0:n_components] irisDataset_reduced = np.dot(eigenvector_subset.transpose(),irisDataset_mean.transpose()).transpose() print(irisDataset_reduced) plt.plot(data[:,0],data[:,1]) plt.title('Before PCA') plt.show() plt.plot(irisDataset_reduced[:,0],irisDataset_reduced[:,1]) plt.title('After PCA') pl

PCA using build in function

 PCA using build in function import matplotlib.pyplot as plt from sklearn import datasets from sklearn.preprocessing import MinMaxScaler import numpy as np iris=datasets.load_iris() data=np.array(iris.data[:10,:2]) scaler=MinMaxScaler() scaler.fit(data) data=scaler.transform(data) print("old data ",data) plt.plot(data[:,0],data[:,1]) plt.title('Before PCA') plt.show() from sklearn.decomposition import PCA pca=PCA(n_components=2) pca.fit(data) newData=pca.transform(data) print(data.shape,newData.shape) print("new Data ",newData) plt.plot(data[:,0],data[:,1]) plt.title('After PCA') plt.show()

Principle Component Analysis (PCA)

 Principle Component Analysis (PCA) This is Machine Learning based algorithm lies under the Unsupervised Learning. This is the simplest code using python import matplotlib.pyplot as plt from sklearn import datasets import numpy as np iris=datasets.load_iris() data=np.array(iris.data[:10,:2]) xdata=data[:,0] ydata=data[:,1] n=len(xdata) print(n) x=np.mean(xdata) y=np.mean(ydata) c=np.cov(xdata,ydata) values, vector = np.linalg.eig(c) values[::-1].sort() vector_subset = vector[:,0:2] values_subset = np.dot(vector_subset.transpose(),values.transpose()).transpose() print("Vector Subset is ",vector_subset) print("Values Subset ",values_subset) plt.plot(values,vector[:,0]) plt.title('After PCA') plt.xlabel('PC1') plt.ylabel('PC2') plt.legend() plt.show() plt.plot(xdata,ydata) plt.title('Before PCA') plt.xlabel('PC1') plt.ylabel('PC2') plt.legend() plt.show()

AI Based Packman Game

 AI Based Packman Game This is completely scratch code for packman using very simple manner using python. We can also say that this is a Mini Project based on AI. Even I did not use the Numpy in this Code. actions=["Move Right","Move Left","Move Up","Move Down","Eat Food","Eat power pallet","Avoid Gost","Eat Ghost"] percepts=[['p','pp','f','pp'], ['f','g','f','pp'], ['pp','f','pp','g'], ['pp','f','g','f']] wlr1=[0,1] wlr2=[2,1] wlr3=[3,0] wll1=[0,2] wll2=[2,2] wll3=[3,1] wlr=[wlr1,wlr2,wlr3] wll=[wll1,wll2,wll3] m=len(percepts) n=len(percepts[0]) wlrm=len(wlr) wllm=len(wll) wlm=len(percepts[0]) class Agent(): def __init__(self): self.currentAction=0 self.r=0 self.c=0 self.power=False self.chwlr=False

Min Max Itrative Algorithm

 Min Max Algorithm This is backtracking algorithm by nature but I try to make this algorithm using iterative manner using python. We mostly use this Min Max algorithm in games. This is scratch code using Numpy import numpy as np import math arr=np.array([-1,8,-3,-1,2,1,-3,4]) k=0 def MinMax(temp1,minmax,h): for j in range(0,h): k=0 for i in range(0,len(temp1)-1,2): if(minmax==1): temp1[k]=max(temp1[i],temp1[i+1]) k=k+1 else: temp1[k]=min(temp1[i],temp1[i+1]) k=k+1 if minmax==1: minmax=0 else: minmax=1 return temp1[0] print(MinMax(arr,1,3))

K-Mean Clustering using Hamming Distance

 K-Mean Clustering using Hamming Distance I already uploaded the post for K-Mean Clustering but that was using Euclidean distance and now I made this algorithm using Hamming Distance. This is completely scratch code which I made using Numpy. This will be good if you understand the topic of k-mean clustering.  import numpy as np var=np.array([["small","green","Irregular","no"],["large","red","irregular","yes"],["large","red","circle","yes"], ["large","green","circle","no"],["large","green","irregular","no"],["small","red","circle","yes"], ["large","green","irregular","no"],["small","red","irrgular","no"],["small","green",&q

K-Mean Clustering

 K-Mean Clustering K-mean clustering is also one of the most popular algorithm of Machine Learning lies in unsupervised learning. It works by making clusters. You have to clear the concept about the k-mean clustering before understanding this code. Furthermore, this algorithm is in scratch format using simple Numpy and also we using matplotlib for plotting the data.  import numpy as np import matplotlib.pyplot as plt var=np.array([[1.0,1.0],[1.5,2.0],[3.0,4.0],[5.0,7.0],[3.5,5.0],[4.5,5.0],[3.5,4.5]]) if len(var)>1: centroid1=var[0] centroid2=var[1] x=y=0 plot1=np.array([centroid1]) plot2=np.array([centroid2]) x+=1 y+=1 for i in range(2,len(var)): ed1=np.sqrt(((centroid1[0]-var[i][0])**2)+((centroid1[1]-var[i][1])**2)) ed2=np.sqrt(((centroid2[0]-var[i][0])**2)+((centroid2[1]-var[i][1])**2)) if(ed1>ed2): centroid2[0]=(centroid2[0]+var[i][0])/2 centroid2[1]=(centroid2[1]+var[i][1])/2 plot

Constraint Satisfaction Problem

 Constraint Satisfaction Problem  This is one of the most popular Machine Learning based algorithm and code for this is given below in python using Numpy in scratch format. import numpy as np rooms={'A':'','B':'A','C':'B','D':'','E':'','F':'D'} person={'x':['P'],'y':['P'],'z':['P'],'a':['Q'],'b':['Q'],'s':['R']} contory=['P','Q','R'] hotelLiving={'A':[],'B':[],'C':[],'D':[],'E':[],'F':[]} count=0 for i in hotelLiving: for j in person: for z in rooms: if(rooms[z]==''): for a in hotelLiving: if hotelLiving[a]==[j]: count+=1 break if count==0: if hotelLiving[z]==[]:

HTML Feedback Form

 HTML Feedback Form Here is the code to create the feedback form using html simple tags. I know here are too much new tags but they are actually too useful and simple to use. You should only need to understand how to use and decide where to use. Here in simple words the only tag which is used is the input type and remaining part is actually the decision. You need to learn the input tag only and remaining tags we discussed before. So you should test this code by your self also try to understand that how they are working. To make the lists I already shared the code before in other coding Blog.  <html> <head> <title> Make it easy </title> <body> <font size =" 6 "> <b> <h> Feedback Form </b> </h> </font> <form> <b> Name </b> </br> <input type =" text " name =" name "> <br> <b> Email </b> <br> <input type =" text &q

HTML creating table

  HTML Creating Table Here is the totally new thing for the beginner. Actually Making a table in html is little bit tricky so here is the code. You cannot understand this unless you try this table by yourself. You should add your own way for making a table.  In the code below there are some tags which all are necessary for the construction of the table such as table for creating table, tr for rows, th for columns, colspan to remove the column or number of column where a column should span and border to create border. <html> <head> <Title> Creating Table </Title> </head> <body> <center> <h> <hr> <font size =" 5 "> Task 1 <hr> </font> </h> <table border =" 5 "> <tr> <th colspan =" 2 "> Table Title </th> </tr> <tr> <th> Column1 </th> <th> Column2 </th> </tr> <tr> <td> Date1 <

HTML bolt and heading tags

  So there are two new tags which are bolt and h1 tag. h1 tag is the tag to show the heading of the content and we uses B tag to make bolt to the text. These tags help to enhance the beauty of the page. <html> <head> <title> Main Heading... </title> </head> <body> <h1> Peragraph </h1> this is the peragraph to learn the html. <br> <B> So we will </B> make a peragraph. </body> </html>

HTML CV

  HTML CV So this is the CV which is made up of simple html tags and also there are some new tags here. Also I know this code is not too accurate but this is the simple enough code for a beginner to understand. Here the important tag is image source and syntax for the tag is given below with the green color text and its is uses to add the picture on the webpage. Also Here I use the center tag to place the content in center you can check the output by place the code in Notepad with .html format after this you can see by open this.   <html> <head> <title> CV(Curriculum vitae) </title> </head> <body> <center> <b> <i> <font size =" 8 "> <hr> <u> Aslam Ali CV </u> <hr> </font> </i> </b> </center> <img src =" Here add the picture location " style =" width:200px " ;"height:200px"; > <style="float:left&quo

HTML add Hyperlink

  HTML add Hyperlink So here I am going to add a new tag which is how to add the hyperlink. Here I want to share a tag which I did not tell you in previous html code so that tag is <br> which is uses to break the line and now we can start with our topic so the tag which I want to tell you is <a href="add link here"> Here you can add the name </a> So, by using this tag we can add the hyperlink to our page in very easy manner. Also here I used the tag to increase the font size which I were tell you in my previous post. <html> <head> <title> add hyperlink </title> </head> <body> i am going to add hyperlink <br> <b> In HTML </b> <font size =" 7 "> Hyperlink <br> </font> <a href =" https://www.google.com/?as_qdr=all "> google </a> </body> </html>