KRAI Practical
KRAI Practical
KRAI Practical
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)
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.
# 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
Output:
Output:
9. SVM classification on any data set
# 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: