KRAI Practical

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Savitribai Phule Pune University, Pune.

ABHINAV EDUCATION SOCIETY'S


INSTITUTE OF MANAGEMENT & RESEARCH (MBA
& MCA),
NARHE PUNE-41
2021-2022

Student Name: Vishal Hanmantrao Sonkamble


SSPU (Seat number): 2032001723
01.Create a data-frame from dictionary of series. Perform
column selection, column addition, column deletion, row
addition and row deletion operations on it.

import pandas as pd
data = [{'a': 100, 'b': 200,'c':300},{'a': 150, 'b': 700, 'c': 500}]
df = pd.DataFrame(data)
print(df)

Output:
02. Find the correlation of the matrix

import pandas as pd

# collect data
data = {
    'x': [45, 37, 42, 35, 39],
    'y': [38, 31, 26, 28, 33],
    'z': [10, 15, 17, 21, 12]
}

# form dataframe
dataframe = pd.DataFrame(data, columns=['x',
'y', 'z'])
print("Dataframe is : ")
print(dataframe)

# form correlation matrix


matrix = dataframe.corr()
print("Correlation matrix is : ")
print(matrix)
Output:
Q3.Plot the Correlation plot on data set and visualize giving
an overview of relationship among data on iris data.
Code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.read_csv("iris.csv")

print (data.head(8))
plt.plot(data.Id, data["SepalLengthCm"], "r--")
plt.show()
data.plot(kind="scatter",
          x='SepalLengthCm',
          y='PetalLengthCm')
plt.grid()
plt.show()

output:
7. Clustering algorithms for unsupervised classification.

# check scikit-learn version


import sklearn

# print(sklearn._version_)
# synthetic classification dataset
from numpy import where
from sklearn.datasets import make_classification
from matplotlib import pyplot

# define dataset
X, y = make_classification(n_samples=100, n_features=2,
n_informative=2, n_redundant=0, n_clusters_per_class=1,
random_state=4)
# create scatter plot for samples from each class

for class_value in range(2):


# get row indexes for samples with this class
row_ix = where(y == class_value)
# create scatter of these samples
pyplot.scatter(X[row_ix, 0], X[row_ix, 1])

# show the plot


pyplot.show()

Output:

8. Bayesian classification on any dataset


# load the iris dataset
from sklearn.datasets import load_iris
iris = load_iris()

# store the feature matrix (X) and response vector (y)


X = iris.data
y = iris.target

# splitting X and y into training and testing sets


from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.4, random_state=1)

# training the model on training set


from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
gnb.fit(X_train, y_train)

# making predictions on the testing set


y_pred = gnb.predict(X_test)
# comparing actual response values (y_test) with predicted
response values (y_pred)
from sklearn import metrics
print("Gaussian Naive Bayes model accuracy(in %):",
metrics.accuracy_score(y_test, y_pred)*100)

Output:
9. SVM classification on any data set

# importingscikit learn with make_blobs


from sklearn.datasets import make_blobs
import numpy as np

import matplotlib.pyplot as plt

# creating datasets X containing n_samples


# Y containing two classes
X, Y = make_blobs(n_samples=500, centers=2,
random_state=0, cluster_std=0.40)

# plotting scatters
plt.scatter(X[:, 0], X[:, 1], c=Y, s=50, cmap='spring');
plt.show()
# creating line space between -1 to 3.5
xfit = np.linspace(-1, 3.5)

# plotting scatter
plt.scatter(X[:, 0], X[:, 1], c=Y, s=50, cmap='spring')
# plot a line between the different sets of data
for m, b, d in [(1, 0.65, 0.33), (0.5, 1.6, 0.55), (-0.2, 2.9, 0.2)]:
yfit = m * xfit + b
plt.plot(xfit, yfit, '-k')
plt.fill_between(xfit, yfit - d, yfit + d, edgecolor='none',
color='#AAAAAA', alpha=0.4)

plt.xlim(-1, 3.5)
plt.show()

output:
11. Write a program to implement RNN (Recurrent neural
network)

import numpy as np
import math
import pylab
import matplotlib.pyplot as plt
import seaborn as sns
sin_wave = np.array([math.sin(x) for x in np.arange(200)])
plt.plot(sin_wave[:50])
plt.show()

Output:
12 Web scraping experiments

Code:
import requests
from bs4 import BeautifulSoup
req
=requests.get("https://www.javatpoint.com/")
s = BeautifulSoup(req.content ,
"html.parser")
res = s.title
print (res)

output:

You might also like