ML Practical File
ML Practical File
Ludhiana
Machine Learning
PRACTICAL FILE
NAME: Saurav
SUBJECT: Machine Learning
UNIV.ROLL.NO: 2123397
SUBMITTED TO: Ms. Navkiran Gill
OFFICIAL E-MAIL ADDRESS: [email protected]
Table of Contents
Sr No Topics Page No
import pandas as pd
data = pd.read_csv("1.csv")
d
1
Task 2: Pre-Processing of Data
data.head()
data.tail()
data.isnull()
2
data.dropna()
data.fillna(0)
3
data.fillna(method="ffill")
data.fillna(method="bfill")
4
Task 3: Linear Regression sklearn, matplotlib and seaborn
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
score_df.describe()
5
X = score_df.iloc[:, :-1].values
y = score_df.iloc[:, 1].values
#In this case, setting random_state=0 ensures that the random splitting of the
data into
#training and testing sets is the same every time you run the code with the same
dataset.
#This reproducibility can be useful for debugging, sharing code, or ensuring
consistent results in different runs.
LinearRegression()
y_pred = regressor.predict(X_test)
plt.scatter(X_train, y_train,color='g')
plt.plot(X_test, y_pred,color='k')
plt.xlabel("Hours", fontsize=15)
plt.ylabel("Score", fontsize=15)
plt.show()
6
Task 4: Write a program to demonstrate the working of the
decision tree algorithm. Use an appropriate data set for building
the decision tree and apply this knowledge to classify a new
sample.
7
8
9
Task 5: Write a program to demonstrate the working of the
Random Forest algorithm.
10
11
Task 6: Write a program to implement the naïve Bayesian classifier for
a sample training data set stored as a .CSV file. Compute the accuracy
of the classifier, considering few test data sets.
12
13
14
Task 7: Write a program to implement k-Nearest Neighbour
algorithm to classify the iris data set. Print both correct and
wrong predictions. Java/Python ML library classes can be used
for this problem
15
16
Task 8: Write a program to demonstrate the working of the K-
means clustering algorithm.
17
18
19
Task 9: Write a program to demonstrate the working of the
Support Vector Machine for Classification Algorithm.
20
21
22