-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uploaded data of Day(3,4,5) Successfully! 😎
- Loading branch information
1 parent
a60a34f
commit f2e4945
Showing
12 changed files
with
10,776 additions
and
0 deletions.
There are no files selected for viewing
1,839 changes: 1,839 additions & 0 deletions
1,839
DAY-4_SUMMER_TRAINING_AIML/Day_4_DHRUVDHAYAL_AI_ML.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1,480 changes: 1,480 additions & 0 deletions
1,480
DAY-5_SUMMER_TRAINING_AIML/Day_5_DHRUVDHAYAL_AI_ML.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,384 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Day-5_DHRUVDHAYAL_AI/ML.ipynb | ||
Automatically generated by Colab. | ||
Original file is located at | ||
https://colab.research.google.com/drive/19OXvgcpMRY0mhkAEBHN6MeOPG2EvWzOa | ||
#MACHINE LEARNING. | ||
We, will train and test the model such that , model can learn from previous past experiences, surrounding of it's enviornment, by gathering and collecting all data & information in the form of a Knowledge then, it will practically Implement in rel-world implementations to perform all the task and behave just as like a Humans called as "Machine Learning". | ||
#1. Supervised Learning | ||
#2. Unsupervised Learning. | ||
#3. Other Tools and Techniques like: SVM, RainForest Methods, etc. | ||
""" | ||
|
||
from sklearn import datasets; #Used for Importing the Valueable Datasets Values. | ||
from sklearn import svm; #Used for Classification Modelling svm-support vector Machines. | ||
from sklearn import metrics; #Used for Evaluation of the Model. | ||
from sklearn import model_selection; #Used for Model Selection. | ||
|
||
#Now, load the main_datasets; | ||
data=datasets.load_digits(); | ||
print(type(data)); | ||
#print("\n Given Data is: \n\n",data); | ||
|
||
#Now, printing the Values of the Data. | ||
print("\n --> Given Values of the Data are: \n\n",data); | ||
|
||
#Now, we need to describe the values of the data. | ||
print(data.DESCR); | ||
|
||
#Now, after Implementing the Main datasets. | ||
#We, need to divide it ir further in training and testing phase. | ||
#Now, in this, we have to get feature extraction of attributes(data) & labels. | ||
X=data.data; | ||
print(type(X)); | ||
print(X.shape); | ||
Y=data.target; | ||
print(type(Y)); | ||
print(Y.shape); | ||
#Here, X->Represents the values of the Data and Information in the form of the Attributes. | ||
#Next, Y->Represents the Values of the Labels for each Datasets Attributes. | ||
|
||
#Now, we are representing the Values of the datasets data in the form of the Digits. | ||
import matplotlib.pyplot as plt; | ||
import matplotlib.image as mpimg; | ||
import numpy as np; | ||
|
||
#Visualise the Data Images. | ||
image=data.images; | ||
y=data.target; | ||
print(type(image)); | ||
print(image.shape); | ||
num=1270; | ||
sample_im=image[num,:,:]; | ||
label=y[num]; | ||
plt.figure(1,figsize=(5,5)); | ||
plt.imshow(sample_im,cmap="gray"); | ||
plt.title(" Actual Target: "+str(label)); | ||
plt.axis("off"); | ||
|
||
#Now, we are just representing the Values of the Data and Information in the form of the Images present in the given Datasets. | ||
import matplotlib.pyplot as plt; | ||
import matplotlib.image as mpimg; | ||
import numpy as np; | ||
|
||
#Visualise the Given Datasets. | ||
image=data.images; | ||
y=data.target; | ||
print(type(image)); | ||
print(image.shape); | ||
num=1270; | ||
sample_im=image[num,: ,:]; | ||
label=y[num]; | ||
plt.figure(1,figsize=(5,5)); | ||
plt.imshow(sample_im,cmap="gray"); | ||
plt.title(" Acual Target : "+str(label)); | ||
plt.axis("off"); | ||
plt.show(); | ||
|
||
"""#Task-1 | ||
--> Solve, the Problem Statement that you need to show the collection of data and infromation in datasets in the form of random numbers and represent it in the form of the 7*7 Matrix randomly form of Representations. | ||
""" | ||
|
||
#First, we need to implement the values of the Libraries. | ||
import matplotlib.pyplot as plt; | ||
import matplotlib.image as imag; | ||
import numpy as np; | ||
|
||
#Visualising the Values of the Data. | ||
images=data.images; | ||
y=data.target; | ||
print("\n Type of the Images in Datasets: ",type(image)); | ||
print("\n Total Length of the Images Data are: ",image.shape); | ||
|
||
#Now, making the 7*7 Matrix to generate the Random Numbers from the datasets and arrange it in the proper manner. | ||
for i in range(49): | ||
num=np.random.randint(0,1797); | ||
samples_im=images[num,: ,: ]; | ||
label=y[num]; | ||
plt.subplot(7,7,i+1); | ||
plt.figure(1,figsize=(8,6)); | ||
plt.imshow(samples_im,cmap="gray"); | ||
#plt.title(" Actual Target: "+str(label)); | ||
plt.axis("off"); | ||
|
||
#Now, we need to show the Values of datasets in the form of random Images. | ||
#Importing all the Libraries of it! | ||
import matplotlib.pyplot as plt; | ||
import matplotlib.image as imag; | ||
import numpy as np; | ||
|
||
#Visualise the Values of the Data. | ||
image=data.images; | ||
y-data.target; | ||
print("\n --> Type of the Image is: ",type(image)); | ||
print("\n --> Total Length of the Images Data are: ",image.shape); | ||
num=1270; | ||
sample_im=image[num, : , :]; | ||
label=y[num]; | ||
plt.figure(1,figsize=(5,5)); | ||
plt.imshow(sample_im,cmap="gray"); | ||
plt.title(" Actual Target: \n"+str(label)); | ||
plt.axis("off"); | ||
plt.show(); | ||
|
||
#Now, representing all the data and information in the datasets randomly representation by using the (7*7) Matrix. | ||
import matplotlib.pyplot as plt; | ||
import matplotlib.image as imag; | ||
import numpy as np; | ||
|
||
#Visualising the values of the Data. | ||
image=data.images; | ||
y=data.target; | ||
print("\n --> Type of the Images present in the Datasets are: ",type(image)); | ||
print("\n --> Total Length of the Datasets present in Images are: ",image.shape); | ||
|
||
for i in range(49): | ||
num=np.random.randint(0,1797); | ||
samples_imp=image[num, : , :]; | ||
label=y[num]; | ||
plt.subplot(7,7,i+1); | ||
plt.figure(1,figsize=(8,6)); | ||
#plt.title(" Actual Target: "+str(label)); | ||
plt.imshow(samples_imp,cmap="gray"); | ||
plt.axis("off"); | ||
|
||
#Showing the Values of the main Iamges (7*7) Matrix. | ||
plt.show(); | ||
|
||
"""#Task-2. | ||
--> Our Main, Task is to generate all the random numbers but in the ascending order. | ||
""" | ||
|
||
#Importing all the Required and needed Libraries. | ||
import matplotlib.pyplot as plt # Fixed import for subplot | ||
import matplotlib.image as imag | ||
import numpy as np; | ||
|
||
#Visuaising the Main data values. | ||
image=data.images; | ||
y=data.target; | ||
print("\n --> Type of the Data contained in particular datasets: ",type(image)); | ||
print("\n --> Total Size of the Image Datasets are: ",image.shape); | ||
|
||
for i in range(100): | ||
num=np.random.randint(0,1797); | ||
samples_imp=image[num, : , :]; | ||
label=y[num]; | ||
plt.subplot(10,10,i+1); # Now using plt for subplot | ||
plt.figure(1,figsize=(9,7)); | ||
plt.imshow(samples_imp,cmap="gray"); | ||
#plt.title(" Actual Target: "+str(label)); | ||
plt.axis("off"); | ||
|
||
#Showing the Valued Graph given Below! | ||
plt.show(); | ||
|
||
#Importing all the Required and needed Libraries. | ||
import matplotlib.pyplot as plt # Fixed import for subplot | ||
import matplotlib.image as imag | ||
import numpy as np; | ||
|
||
#Visuaising the Main data values. | ||
image=data.images; | ||
y=data.target; | ||
print("\n --> Type of the Data contained in particular datasets: ",type(image)); | ||
print("\n --> Total Size of the Image Datasets are: ",image.shape); | ||
|
||
# Figure out the index of each digit | ||
digit_indices = [np.where(y == i)[0] for i in range(10)] | ||
|
||
# Plot digits in increasing order | ||
fig, axes = plt.subplots(10, 10, figsize=(9, 7)) | ||
for i in range(10): | ||
for j in range(10): | ||
index = digit_indices[i][j] | ||
axes[i, j].imshow(image[index], cmap="gray") | ||
axes[i, j].axis("off") | ||
|
||
#Showing the Graph Finally! | ||
plt.show() | ||
|
||
#Now, we have to split the values of the Benchmark. | ||
# like: 60:40 Ratio's. | ||
# Let's we have the 70:40 Ratio, so it contain 70-Testing, 40-Training. | ||
# 80 : 20. | ||
ratio=0.3; #Ratio = 0.3 defines that 30% Data split it into the Testing Phase. | ||
Xtrain,Xtest,ytrain,ytest=model_selection.train_test_split(X,y,test_size=ratio,random_state=5); | ||
print("\n 1. Training Datasets: ",Xtrain.shape," ",ytrain.shape); | ||
print("\n 2. Testing Datasets: ",Xtest.shape," ",ytest.shape); | ||
|
||
"""#Creating the Classification Model by using the SVM. | ||
#(SVM) Stands for "Support Vector Machine". | ||
""" | ||
|
||
#Creating the Classification Model by using the SVM. | ||
# Support vector Machine (SVM). | ||
clf_model=svm.SVC(); | ||
|
||
#We, need to train the Model by using the Training Datasets. | ||
clf_model=clf_model.fit(Xtrain,ytrain); | ||
|
||
#We, need to pass the Trained model in terms of testing. | ||
#we, also mention labels of testing data. | ||
ypred=clf_model.predict(Xtest); | ||
|
||
#Showing the Classification of that model. | ||
print(ypred.shape); | ||
print(ytest.shape); | ||
|
||
#Now, we need to measure the overall performance and accuracy in order to measure. | ||
|
||
acc=metrics.accuracy_score(ypred,ytest); | ||
conf_matrix=metrics.confusion_matrix(ypred,ytest); | ||
report=metrics.classification_report(ypred,ytest); | ||
|
||
#=============== Printing and Displaying all the Values! =============== | ||
|
||
print("\n 1. Total Accuracy of the Model are: ",acc); | ||
print("\n-------------------------------------------------------"); | ||
|
||
print("\n 2. Confusion Matrix given here: \n\n",conf_matrix); | ||
print("\n-------------------------------------------------------"); | ||
|
||
print("\n 3. Classification overall report: \n\n",report); | ||
print("\n-------------------------------------------------------"); | ||
|
||
"""#Confusion Matrix of that Particular Datasets.""" | ||
|
||
#We, are showing the Values of the Confusion Matrix are given Below! | ||
import seaborn as sns; | ||
sns.heatmap(conf_matrix,annot=True,cmap='jet'); | ||
plt.title(" Confusion Matrix showing the Digit Datasets!"); | ||
plt.show(); | ||
|
||
"""#Task-4 | ||
--> 1. Load the iris Data-Sets. | ||
--> 2. Understand the Dataset and describe by 'DESCR'. | ||
--> 3. And Implement the 70:30 & 60:40 Train Test Split. | ||
--> 4. And Compare it's Accuracy, Precision, Reacll & F1-Score. | ||
--> 5. For, Each Split. | ||
""" | ||
|
||
#Now, we are the the Iris-Datasets. | ||
from sklearn import datasets; | ||
from sklearn import svm; | ||
from sklearn import model_selection; | ||
from sklearn import metrics; | ||
|
||
#Visualise and load the Datasets Simply! | ||
data=datasets.load_iris(); | ||
print(type(data)); | ||
|
||
#Now, we have to show the Values of the Data. | ||
print("\n 1. Given Iris Datasets after Loading properly Given Below! : \n\n",data); | ||
#print("\n 2. Total Length of the Iris-Datasets are: ",data.shape); | ||
|
||
#Understand the Dataset and describe by 'DESCR'. | ||
#Describing the Datasets are by using the DESCR. | ||
print(data.DESCR); | ||
|
||
#Now, we splitting the Datasets into ration of Testing and Training Phases. | ||
ratio=0.3; | ||
Xtest,Xtrain,ytest,ytrain=model_selection.train_test_split(X,y,test_size=ratio,random_state=5); | ||
print("\n 1. Training Datasets: ",Xtrain.shape," ",ytrain.shape); | ||
print("\n 2. Testing Datasets: ",Xtest.shape," ",ytest.shape); | ||
|
||
#Now, we need to train the Modelby using the SVM. | ||
#SUPORT VECTOR MACHINE - (SVM) generally used for classification of the Models. | ||
clf_model=svm.SVC(); | ||
|
||
#Train the Model in terms of training. | ||
clf_model=clf_model.fit(Xtrain,ytrain); | ||
|
||
#Now, mention the labels in testing for classifications. | ||
#Now, we used to predict by the trained model. | ||
ypred=clf_model.predict(Xtest); | ||
|
||
#Showing the Actual Label and predicted Labels. | ||
print("\n Predicted Values: ",ypred.shape); | ||
print("\n Testing Values: ",ytest.shape); | ||
|
||
#Now, we need to compare it's valius of the Accuracy, Precision, and it's F1-Score. | ||
|
||
acc=metrics.accuracy_score(ypred,ytest); | ||
confu_matrix=metrics.confusion_matrix(ypred,ytest); | ||
report=metrics.classification_report(ypred,ytest); | ||
|
||
#Printing and Displaying all the Values in the Iris Classifications are given Below! | ||
|
||
print("\n---------------------- IRIS DATASETS PERFORMANCE ----------------------"); | ||
|
||
print("\n 1. Total Accuracy are: ",acc); | ||
print("\n---------------------------------------------------------"); | ||
|
||
print("\n 2. Confusion Matrix are Given Below! \n\n",confu_matrix); | ||
print("\n---------------------------------------------------------"); | ||
|
||
print("\n 3. Classification Report have been given Below! \n\n",report); | ||
print("\n---------------------------------------------------------"); | ||
|
||
# We, also show the values of the Confusion Matrix. | ||
import seaborn as sns; | ||
import matplotlib.pyplot as plt; | ||
|
||
sns.heatmap(confu_matrix,annot=True,cmap="jet"); | ||
plt.title("Iris Recognization Datasets with Labels!"); | ||
|
||
#Showing the finall plotting of the Graph. | ||
plt.figure(1,figsize=(10,8)); | ||
plt.show(); | ||
|
||
# load the iris dataset | ||
# understand the datset from its DESCR | ||
# and implement the 60:40 and 70:30 ratio train test split | ||
# and compare its acc, precision, recall and f1_score | ||
# for each split | ||
|
||
from sklearn import metrics,datasets,model_selection,svm | ||
data = datasets.load_iris() | ||
|
||
X = data.data | ||
y = data.target | ||
Result = np.zeros((2,4)) | ||
ratio= [0.4,0.3] | ||
for i in range(len(ratio)): | ||
Xtrain,Xtest,ytrain,ytest = model_selection.train_test_split(X,y,test_size=ratio[i],random_state=5) | ||
# create the model | ||
clf_model = svm.SVC() | ||
# train the model | ||
clf_model = clf_model.fit(Xtrain,ytrain) | ||
# test the model | ||
ypred = clf_model.predict(Xtest) | ||
|
||
# accuracy | ||
temp_acc = metrics.accuracy_score(ypred,ytest) | ||
# precision | ||
temp_pre = metrics.precision_score(ypred,ytest,average='macro') | ||
# recall | ||
temp_rec = metrics.recall_score(ypred,ytest,average='macro') | ||
# f1 score | ||
temp_f1 = metrics.f1_score(ypred,ytest,average='macro') | ||
|
||
list_result = [temp_acc,temp_pre,temp_rec,temp_f1] | ||
Result[i,:]=list_result | ||
|
||
print(Result) | ||
res = ['Accuracy','Precision','Recall','F1_score'] | ||
|
||
import pandas as pd | ||
res_df = pd.DataFrame(Result,columns=res,index=['60:40','70:30']) | ||
print(res_df) | ||
|
||
res_df.T.plot(kind = 'bar') | ||
|
||
"""#----Here,isthe END OF DAY-5 Based on SupervisedLearning.---- | ||
#========================== DAY-5 =========================== | ||
""" |
Binary file not shown.
Oops, something went wrong.