AI Practical - Python
Q1. Write a python code to plot a line chart of the dataset [Link].
import pandas
import csv
import [Link] as plt
series = pandas.read_csv('[Link]', header=0, index_col=0)
[Link]()
[Link]()
Q2. Write a python program to do the train-test-split for regression where the test data
should be 20% of the dataset and the rest should be train data.
import pandas as pd
import [Link] as plt
from sklearn.model_selection import train_test_split
from [Link] import load_iris
data=pd.read_csv('[Link]')
print([Link]())
y=[Link]
x=[Link]('temp',axis=1)
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)
print(x_train.head())
print("Shape of training")
print(x_train.shape)
x_test.head()
print("Shape of testing")
print(x_test.shape)
Q3. Write a Java code to find RMSE, MSE, AMSE for the given data points: (1,1), (2,1),
(3,2), (4,2), (5,4) and corresponding predicted values [0.6,1.29,1.99,2.69,3.4] where
regression line equation is Y' = 0.7X – 0.1
from [Link] import mean_squared_error, mean_absolute_error,
mean_absolute_percentage_error
import math
Y_true = [1,1,2,2,4]
Y_pred = [0.6,1.29,1.99,2.69,3.4]
print("MSE = ", mean_squared_error(Y_true,Y_pred))
print("RMSE = ", [Link](mean_squared_error(Y_true,Y_pred)))
print("MAE = ", mean_absolute_error(Y_true,Y_pred))
print("MAPE = ", mean_absolute_percentage_error(Y_true,Y_pred))