Fardin IBM
Fardin IBM
-F/TL/021
REV.00Date 20.03.2020
RECORD NOTEBOOK
DEPARTMENT
OF
NAME : MD FARDIN.V
REGISTER NO : 211191101100
YEAR/SEM/SEC : III/IV/B
2023-2024(EVEN SEMESTER)
FORM NO.-F/TL/021
REV.00Date 20.03.2020
BONAFIDE CERTIFICATE
Register No : 211191101100
MACHINE LEARNING USING WATSON
Name of Lab : STUDIO LAB (BCS19106)
PAGE STAFF
S.NO DATE NAME OF THE EXPERIMENT NO. SIGNATURE
7. 11/03/2024 34
LINEAR REGRESSION IN R
1. CREATE A LIST IN R
Aim :
To create the program for List by using R programming
Procedure :
Step 1 : Open R studio – New- New script and R programming work area will
get created with console and environment .
Step 2 : Create list by declaring variable in vector
Step 3: By using list () , data will get created inside List .
Step 4 : Select the element from the list by index value .
Step 5 : To find the length use Len() and more list function to atchive List
operations.
Step 6: To merge two list we use merge.List
Step 7: Save the program
Step 8 : Select the entire code and click run .
MD Fardin.V 1 211191101100
Program :
# Creating list
a<-1:5
b<-c("A","b","c","d","e")
c<-3+2i
l<-list(a,b,c)
l
l1<-list("red", 1, c(2,3,4),5.5)
l1
#selecting Elements from list
l[[2]]
l[[2]][4]
l[[c(1,2)]]
l<-list(f=a,s=b,t=c)
l
class(l)
lapply(l, length)
mode(l)
str(l)
list1 <- list(1,2,3)
list2 <- list("S","u","n")
merged.list<- c(list1,list2)
print(merged.list)
list1
MD Fardin.V 2 211191101100
Output :
MD Fardin.V 3 211191101100
Result :
Thus, the above program was successfully executed.
MD Fardin.V 4 211191101100
Date : 22/01/2024
2. CREATE A DATAFRAME IN R
Aim :
To create the program for Data frame by using R programming
Procedure :
Step 1 : Open R studio – New- New script and R programming work area will
get created with console and environment .
Step 2 : Create vector by c( ), pass the value of same datatype
Step 3: By using data. frame() , can convert the List to Dataframe with rows
and column .
Step 4 : To find the mid value use the index [] value that comes in column .
Step 5 : rbind() , we can add the row of the dataframe
Step 6: Adding and sorting operations can also be done
Step 7: Save the program
Step 8 : Select the entire code and click run .
MD Fardin.V 5 211191101100
Program :
#Creating dataframe
name<-c("ram","sam","tom")
age<-c(18,17,16)
mark<-c(430,450,356)
df<-data.frame(name,age,mark)
df
#naming
names(df)<-c("Names","Age","CGPA")
df
df<-data.frame(Name=name,Age=age,CGPA=mark)
df
#Selection
str(df)
df[3,2]
df[3]
df["Age"]
df[c(1,3),c("Age","CGPA")]
df$Name
df[[2]]
# ADDING values
#adding column
dep<-c("BCA","CS","IT")
df$dep<-dep
df
df[["dep"]]<-dep
df
MD Fardin.V 6 211191101100
#adding Row
zam<-data.frame(Name="zam",Age=19,CGPA=415,dep="MBA")
rbind(df,zam)
df
zam
#sorting
sort(df$Age)
ranks<-order(df$Age)
ranks
df$Age
df[ranks,]
MD Fardin.V 7 211191101100
Output :
MD Fardin.V 8 211191101100
Result :
Thus, the above program was successfully executed
MD Fardin.V 9 211191101100
Date : 29/01/2024
3. CREATE PROJECT IN WATSON STUDIO
Aim :
To create the program for project in WATSON STUDIO
Procedure :
Step 1: Open IBM Watson studio and Login using your account. The project
and the catalog must be created by members of the same IBM Cloud account.
Step 2: Click New project on the home page or on your Projects page.
Step 3: Choose whether to create an empty project or to create a project based
on an exported project file or a sample project.
Step 4: On the New project screen, add a name and optional description for the
project.
Step 5: After giving name , create the storage by clicking Define storage .
Step 6: Click Lite plan as it is free
Step 7 : click create at the bottom of the page
Step 8: Finally , Your project was created .
MD Fardin.V 10 211191101099
Output:
MD Fardin.V 11 211191101100
MD Fardin.V 12 211191101100
MD Fardin.V 13 211191101100
Result :
Thus, the above experiment was successfully executed
MD Fardin.V 14 211191101100
Date : 05/02/2024
4. DATA REFINERY-PREPARING THE DATA
Aim :
To create the program for data refinery – preparing the data
Procedure:
Step 1: Open IBM Watson studio and Login using your account. The project
and the catalog must be created by members of the same IBM Cloud account.
Step 1: click Watson studio h8 .
MD Fardin.V 15 211191101100
Step 4: create new project and give next
Step 5: Give project name and description and storage for your project and
click create
MD Fardin.V 16 211191101100
Step 6: Project created successfully .
MD Fardin.V 17 211191101100
Step 8: import dataset -Employee_data with the help of link
Step 9: Data set was imported successfully and click new asset .
MD Fardin.V 18 211191101100
Step 10: After cliking New asset click Data Refinery and give select .
MD Fardin.V 19 211191101100
Step 11: Refinery process will start working .
MD Fardin.V 20 211191101100
Step 12: Click on a new step and aggricate and select the column and operation
and create a new colunm name and give Apply .
Result :
Thus, the above experiment was successfully executed
MD Fardin.V 2 211191101100
1
Date : 19/02/2024
5. Visualization data in Watson studio
Aim :
To create the program for Visualization data in Watson Studio
Procedure :
Step 1: Open IBM Watson studio and Login using your account. The project
and the catalog must be created by members of the same IBM Cloud account.
Step 1: click Watson studio h8 .
MD Fardin.V 2 211191101100
2
Step 3: click launch in IBM cloud park data
MD Fardin.V 2 211191101100
3
Step 5: Give project name and description and storage for your project and
click create
MD Fardin.V 2 211191101100
4
Step 7: Click assets and inset data set
MD Fardin.V 2 211191101100
5
Step 9: Data set was imported successfully and click new asset .
Step 10: After cliking New asset click Data Refinery and give select .
MD Fardin.V 2 211191101100
6
Step 11: Refinery process will start working .
MD Fardin.V 2 211191101100
7
Step 12: Click on a new step and do filtering ,select column name as first name
and select the operation ends with and select text and give “e” and click Apply .
Step 13: first name was end up with “e” successfully and click visualization .
MD Fardin.V 2 211191101100
8
Step 14: Give x axis and split by and visualization will exist successfully .
Step 15: Select the chart as per requirement and do visualization in watson
studio .
Result :
Thus, the above experiment was successfully executed
MD Fardin.V 2 211191101100
9
Date : 04/03/2024
6. K-Means Clustering
Aim :
To create a program to implement the K means clustering algorithm
Procedure :
Step 1: Import Necessary Libraries numpy for numerical operations &
matplotlib.pyplot for visualization
Step 2: Generate or Load Data: you can either generate synthetic data or load
data from a dataset.
Step 3: Initialize Centroids:Choose K random data points from the dataset as
initial centroids.
Step 4: Assign Data Points to Nearest Centroid: Calculate the Euclidean
distance between each data point and each centroid. Assign each data point to
the nearest centroid
Step 5: Update Centroids: Recalculate the centroid of each cluster by taking the
mean of all data points assigned to that cluster.
Step 6: Visualize Clusters : Plot the data points and centroids to visualize the
clusters.
MD Fardin.V 2 211191101100
10
Program :
import numpy as np
import matplotlib.pyplot as plt
def generate_data(num_samples, num_features, num_clusters):
data = np.zeros((num_samples, num_features))
for i in range(num_clusters):
center = np.random.randn(num_features) * 10 # Random center for each
cluster
data[i * (num_samples // num_clusters):(i + 1) * (num_samples //
num_clusters)] = np.random.randn(
num_samples // num_clusters, num_features) + center
return data
def initialize_centroids(data, k):
centroids = data[np.random.choice(data.shape[0], k, replace=False)]
return centroids
def assign_to_nearest(data, centroids):
distances = np.sqrt(((data - centroids[:, np.newaxis])**2).sum(axis=2))
labels = np.argmin(distances, axis=0)
return labels
def update_centroids(data, labels, k):
centroids = np.zeros((k, data.shape[1]))
for i in range(k):
centroids[i] = np.mean(data[labels == i], axis=0)
return centroids
# Step 6: Repeat Steps 4 and 5 until convergence
MD Fardin.V 2 211191101100
1
def k_means(data, k, max_iters=100):
centroids = initialize_centroids(data, k)
for _ in range(max_iters):
old_centroids = centroids
labels = assign_to_nearest(data, centroids)
centroids = update_centroids(data, labels, k)
if np.all(old_centroids == centroids):
break
return labels, centroids
def visualize_clusters(data, labels, centroids):
plt.figure(figsize=(8, 6))
plt.scatter(data[:, 0], data[:, 1], c=labels, cmap='viridis', s=50, alpha=0.5)
plt.scatter(centroids[:, 0], centroids[:, 1], c='red', s=200, marker='X')
plt.title('K-Means Clustering')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.show()
# Generating synthetic data
num_samples = 300
num_features = 2
num_clusters = 3
data = generate_data(num_samples, num_features, num_clusters)
# Performing K-means clustering
k=3
labels, centroids = k_means(data, k)
# Visualizing clusters
visualize_clusters(data, labels, centroids)
MD Fardin.V 2 211191101100
2
Output :
Result :
Thus, the above experiment was successfully executed
MD Fardin.V 2 211191101100
3
Date : 11/03/2024
7. Linear Regression in R
Aim :
To create the program for Linear Regression in R Language
Procedure :
Step:1 Create the predictor and response variable.
Step:2 Give the chart file a name
Step:3 Plot the chart and save the chart
Step:4 Predict the values of testing data.
Step 5: save the code by dev.off() and run the code Linner regression plot will
get conformed in console
MD Fardin.V 2 211191101100
4
Program :
# Create the predictor and response variable.
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
relation <- lm(y~x)
MD Fardin.V 2 211191101100
5
Output :
Result :
Thus, the above experiment was successfully execute.
MD Fardin.V 2 211191101100
6
Date : 18/03/2024
8. Decision tree in R programming
Aim :
To create the program for Decision tree in R Language
Procedure :
Step:1 install the needed library – datasets, caTools, Party, Dplyr , mgrittr.
Step:2 Split the dataset into training and testing data.
Step:3 Create a model for decision tree algorithm using R programming
language.
Step:4 Predict the values of testing data.
Step 5: find the accuracy of the decision tree model.
Step 6: Save the code and run the code Decision tree will get conformed in
console.
MD Fardin.V 2 211191101100
7
Program :
library(datasets)
library(caTools)
library(party)
library(dplyr)
library(magrittr)
data("readingSkills")
head(readingSkills)
MD Fardin.V 2 211191101100
8
predict_model<-predict(ctree_, test_data)
m_at <- table(test_data$nativeSpeaker, predict_model)
m_at
Result :
Thus, the above experiment was successfully executed
MD Fardin.V 2 211191101100
9